Muffin-Redis — Redis support for the Muffin framework.
- Built on
redis.asyncio
client. - Optional support for
redislite
with Unix socket configuration. - JSON serialization support
- Automatic connection pool management (blocking or non-blocking).
- Simple
get()
/set()
with optionaljsonify
flag. - Lifecycle support:
startup
andshutdown
integrate with Muffin app lifecycle.
- Python >= 3.10
Install using pip:
pip install muffin-redis
Optionally with redislite
:
pip install muffin-redis[redislite]
Setup the plugin and connect it into your app:
from muffin import Application
from muffin_redis import Plugin as Redis
app = Application('example')
# Initialize the plugin
redis = Redis(address='redis://localhost')
redis.setup(app)
You can now use Redis in your routes:
@app.route('/some_url', methods=['POST'])
async def some_method(request):
value = await redis.get('key')
if value is None:
value = ... # Do some work
await redis.set('key', value, expire=60)
return value
Under the hood, Muffin-Redis uses aioredis for asynchronous Redis support.
Name | Default | Description |
---|---|---|
url |
"redis://localhost" |
Redis connection URL |
db |
None |
Redis DB index |
password |
None |
Redis password |
encoding |
"utf-8" |
Encoding used by the client |
poolsize |
10 |
Max pool size (set 0 to disable pooling) |
decode_responses |
True |
Whether to decode binary responses |
jsonify |
False |
Automatically encode/decode JSON with get/set |
blocking |
True |
Use a blocking connection pool |
timeout |
20 |
Timeout in seconds for getting a connection |
redislite |
False |
Enable redislite usage |
Please report bugs or feature requests at: https://github.com/klen/muffin-redis/issues
Development happens at: https://github.com/klen/muffin-redis
Licensed under the MIT license.
- Created by klen (Kirill Klenov)