【发布时间】:2014-08-16 20:52:51
【问题描述】:
我试图理解这个使用 Gevent 和 Redis pub/sub 的 socket.io 代码。显然subscribe 方法在频道上等待消息。
我可以拥有(数万个)频道,一个频道每个用于向一位用户推送通知和聊天吗?频道是为此而生的吗?
def _sub_listener(socketio, chan):
"""
This is the method that will block and listen
for new messages to be published to redis, since
we are using coroutines this method can block on
listen() without interrupting the rest of the site
"""
red = Redis(REDIS_HOST)
red.subscribe(chan)
for i in red.listen():
socketio.send({'message': i})
【问题讨论】: