没有项目描述

muffin-redis的Python项目详细描述


muffin redis–redis对muffin框架的支持。

Build StatusCoveralshttp://img.shields.io/pypi/v/muffin-redis.svg?style=flat-squarehttp://img.shields.io/pypi/dm/muffin-redis.svg?style=flat-square

Requirements

  • python>;=3.3

Installation

muffin redis应使用pip:

安装
pip install muffin-redis

Usage

在您的muffin应用程序配置中添加muffin_redis到插件。

或者像这样手动安装:

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

app = muffin.Application('test')
app.install(redis)

Appllication configuration options

REDIS_DB–redis数据库数(0) REDIS_HOST–连接IP地址(“127.0.0.1”) REDIS_PORT–连接端口(6379) REDIS_PASSWORD–连接密码(无) REDIS_POOLSIZE–连接池大小(1) REDIS_FAKE–在测试建议中使用假的redis而不是真的redis(false)

Queries

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

Pub/Sub

为此功能,您需要在配置中启用redis_pubsub=true

发布消息非常简单:

@app.register
def view(request):
    yield from app.ps.redis.publish('channel', 'message')

接收更复杂。 为了开始从pubsub接收消息,应该创建订阅管理器。 然后在管理器中打开一个单独的连接, 之后您可以订阅和收听消息:

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还使用接口实现PEP 0492异步,并为接口实现异步, 所以在python 3.5+中,可以用更轻的方式拼写:

async with app.ps.redis.start_subscribe() 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.

为每个订阅管理器创建单独的redis连接可能不太好 (例如,每个websocket),因此可以通过管理订阅的通道掩码来改进 以及重用同一个“pubsub-specific”redis连接。

Bug tracker

如果您有任何建议、错误报告或 烦恼请向问题追踪者报告 在https://github.com/klen/muffin-redis/issues

Contributing

松饼redis的开发发生在:https://github.com/klen/muffin-redis

Contributors

  • klen(基里尔·克莱诺夫)

License

根据MIT license授权。

如果你想对这个项目表示感谢,欢迎你寄来 明信片寄往:

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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java根据两个数组的值对数组进行排序   具有自签名证书和NTLM代理的java Maven SSL repo错误   java自定义字体按钮不工作AndroidStudio   java通过Spring MVC web应用程序向客户端发送文本文件   Java Spring Web服务SOAP身份验证   ANT property environment=“env”无法在JAVA中检索它,但如果作为ANT命令运行,则可以正常工作   java是为spring mvc rest api或spring boot api对应用服务器的每个新请求创建的服务、存储库和组件的新实例吗?   java私有静态最终字符串未完成其工作   PKCS12的安全Java密钥重新处理   java JPA继承表每类SQLSyntaxErrorException