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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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