Skip to content

klen/muffin-redis

Muffin-Redis

Muffin-Redis — Redis support for the Muffin framework.

Tests Status PyPI Version Python Versions


Features

  • 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 optional jsonify flag.
  • Lifecycle support: startup and shutdown integrate with Muffin app lifecycle.

Requirements

  • Python >= 3.10

Installation

Install using pip:

pip install muffin-redis

Optionally with redislite:

pip install muffin-redis[redislite]

Usage

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.

Configuration Options

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

Bug Tracker

Please report bugs or feature requests at: https://github.com/klen/muffin-redis/issues

Contributing

Development happens at: https://github.com/klen/muffin-redis

License

Licensed under the MIT license.

Credits

  • Created by klen (Kirill Klenov)

About

Redis support for Muffin framework

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •