[英]tornado-redis: Why the 'listen' and the 'brpop' of tornado-redis can't work at the same time
像这样的代码:
from tornadoredis import Client
from tornado.ioloop import IOLoop
from tornado.gen import coroutine, Task
rds = Client()
@coroutine
def listen_pub():
def handle(msg):
print msg
yield Task(rds.subscribe, channels='pub')
rds.listen(handle)
@coroutine
def listen_list():
while True:
res = yield Task(rds.brpop, keys='list')
print res
def test():
listen_pub()
listen_list()
test()
IOLoop.current().start()
当我运行上面的代码时,只有'listen_list'可以接收消息。 为什么“ listen_list”不起作用? 如何同时收听来自LIST和PUB / SUB的消息?
看看redis文档:
订阅一个或多个频道的客户端不应发出命令 ,尽管它可以订阅其他频道或从其他频道取消订阅。 SUBSCRIBE和UNSUBSCRIBE操作的答复以消息的形式发送,以便客户端可以读取连贯的消息流,其中第一个元素表示消息的类型。
您必须使用两个连接客户端。
资料来源: http : //redis.io/topics/pubsub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.