每个用户一个 redis 频道?

Jes*_*ose 5 redis socket.io

我试图理解这个使用 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})
Run Code Online (Sandbox Code Playgroud)

yea*_*ght 0

我也在寻找同样的东西。通过搜索,我发现论坛上说 Redis 可以非常有效地处理多达 10k 个通道。但对于如果通道超过 10k 会发生什么,我还没有得到任何绝对的答案。

我目前正在尝试继续共享频道。 这是使用共享通道的示例算法/实现。