Skip to main content

No project description provided

Project description

Muffin-Redis – Redis support for Muffin framework.

Build Status Coverals


  • python >= 3.3


Muffin-Redis should be installed using pip:

pip install muffin-redis


Add muffin_redis to PLUGINS in your Muffin Application configuration.

Or install it manually like this:

redis = muffin_redis.Plugin(**{'options': 'here'})

app = muffin.Application('test')

Appllication configuration options

REDIS_DB – Number of Redis database (0) REDIS_HOST – Connection IP address (“”) REDIS_PORT – Connection port (6379) REDIS_PASSWORD – Connection password (None) REDIS_POOLSIZE – Connection pool size (1) REDIS_FAKE – Use fake redis instead real one for tests proposals (False)


def view(request):
    value = yield from'my_key')
    return value


You need to have enabled REDIS_PUBSUB = True in your configuration for this functionality.

Publishing messages is as simple as this:

def view(request):
    yield from'channel', 'message')

Receiving is more complex. In order to start receiving messages from pubsub, you should create a subscription manager. Then you open a separate connection within that manager, after which you can subscribe and listen for messages:

sub =
yield from # this creates separate connection to redis
# returns that manager itself, so this can be written like this:
# sub = yield from
sub.psubscribe(['channel.a.*', 'channel.b.*']) # you can use masks as well
# now wait for new messages
while True:
    msg = yield from sub.next_published()
    print('got message', msg)
    print('the message itself:', msg.value)
    if shall_stop:
yield from sub.close() # don't forget to close connection!

Subscription manager also implements PEP 0492 async with and async for interfaces, so in Python 3.5+ that can be spelled in lighter way:

async with as sub:
    await sub.subscribe(['channel1'])
    await sub.psubscribe(['channel.a.*', 'channel.b.*']) # you can use masks as well
    async for msg in sub:
        print('got message', msg)
# no need to close connection explicitly
# as it will be done automatically by context manager.

It might be not very good to create separate Redis connection per each subscription manager (e.g. per each websocket), so that could be improved by managing subscribed channel masks and reusing the same single “pubsub-specific” redis connection.

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at


Development of Muffin-Redis happens at:


  • klen (Kirill Klenov)


Licensed under a MIT license.

If you wish to express your appreciation for the project, you are welcome to send a postcard to:

Kirill Klenov
pos. Severny 8-3
MO, Istra, 143500

Project details

Download files

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

Files for muffin-redis, version 1.3.3
Filename, size File type Python version Upload date Hashes
Filename, size muffin_redis-1.3.3-py2.py3-none-any.whl (7.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size muffin-redis-1.3.3.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page