Skip to main content

Distributed Redis caching for discord bots.

Project description

Mirex

Distributed Redis based caching for discord bots.


Mirex makes no guarantees that objects will be saved and restored field for field. The discord API is too unstable to provide correctness in all cases given how frequently fields are added, removed or changed. If you notice a change please open an issue or PR so it can be updated.


Basic example

Given how early in development this library is, this is an extremely simple POC however it does work.

import asyncio
import os

import disnake
from disnake.ext import commands
from redis import asyncio as aioredis

from mirex import Mirex


async def main():
    bot = commands.InteractionBot(intents=disnake.Intents.all())

    redis = aioredis.from_url("redis://127.0.0.1:6379")
    mirex = Mirex(
        namespace=disnake,
        redis_instance=redis,
        connection_state=bot._connection,
    )
    mirex.inject_hooks()
    asyncio.create_task(mirex.consume_queue())
    asyncio.create_task(mirex.consume_eviction())

    @bot.event
    async def on_ready():
        guild_id = ...
        g = await bot.fetch_guild(guild_id)
        mirex.add_to_cache(g)
        guild: disnake.Guild = await mirex.aget_guild(guild_id)
        assert guild == g
        print("Done")

    await bot.start(os.environ["TOKEN"])


asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mirex-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

mirex-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file mirex-0.1.0.tar.gz.

File metadata

  • Download URL: mirex-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for mirex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f72602ff3d8a0db4aac54f57bfae1a757ab902573f7d533b21e755b909539a0
MD5 b6fe2e1cc5b6080a1006437b2fe71ff3
BLAKE2b-256 6d4663d92115d59ce67634d5d334dfa62c88fc9bea4074b1db856f0f9ca18a47

See more details on using hashes here.

File details

Details for the file mirex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mirex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for mirex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 772919a7b597e116094819344426e8d94179f3a3130cc7f920ba28e6f4873dd2
MD5 8969ae345bb4c3f72174dd6339e60924
BLAKE2b-256 a63add2c65f8c78d43994fbec78c5006324943653ffc5f087fb82a52c3ce59e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page