Skip to main content

No project description provided

Project description

Muffin-Redis – Redis support for Muffin framework.

Build Status Coverals http://img.shields.io/pypi/v/muffin-redis.svg?style=flat-square http://img.shields.io/pypi/dm/muffin-redis.svg?style=flat-square

Requirements

  • python >= 3.3

Installation

Muffin-Redis should be installed using pip:

pip install muffin-redis

Usage

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')
app.install(redis)

Appllication configuration options

REDIS_DB – Number of Redis database (0) REDIS_HOST – Connection IP address (“127.0.0.1”) 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)

Queries

@app.register
def view(request):
    value = yield from app.ps.redis.get('my_key')
    return value

Pub/Sub

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

Publishing messages is as simple as this:

@app.register
def view(request):
    yield from app.ps.redis.publish('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 = app.ps.redis.start_subscribe()
yield from sub.open() # this creates separate connection to redis
# sub.open() returns that manager itself, so this can be written like this:
# sub = yield from app.ps.redis.start_subscribe().open()
sub.subscribe(['channel1'])
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:
        break
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 app.ps.redis.start_subscribe() as sub:
    sub.subscribe(['channel1'])
    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 https://github.com/klen/muffin-redis/issues

Contributing

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

Contributors

  • klen (Kirill Klenov)

License

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
Russia

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

muffin-redis-1.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

muffin_redis-1.1.1-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file muffin-redis-1.1.1.tar.gz.

File metadata

File hashes

Hashes for muffin-redis-1.1.1.tar.gz
Algorithm Hash digest
SHA256 15615975d530757793e6421781bffd422b18571bf1feb00574d2dc9da206ef7e
MD5 aad9a35d7cb0839f024730f6d8e2c800
BLAKE2b-256 2e4905237ab8b133e94c2ed66362fdfa24cea9b90045cca6544340cbde2701ab

See more details on using hashes here.

File details

Details for the file muffin_redis-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for muffin_redis-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd16e0decf88746c29928aa3f55426c334c2d43cf6ab9eb86351a8d9176e30e7
MD5 19f39d54b498d20db79f28263b0cacf2
BLAKE2b-256 7e43472b2c7885284a077527f9047ce674791dde6f300624ef1c5d2c2a9a5cc4

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