gpt4 book ai didi

redis - Redis PubSub 订阅机制是如何工作的?

转载 作者:可可西里 更新时间:2023-11-01 11:23:57 25 4
gpt4 key购买 nike

我想创建一个发布-订阅基础架构,其中每个订阅者都将收听多个(比如 10 万个) channel 。

我想为此目的使用 Redis PubSub,但我不确定订阅数千个 channel 是否是这里的最佳做法。为了回答这个问题,我想知道 Redis 中的订阅机制在后台是如何工作的。

另一种选择是为每个订阅者创建一个 channel ,并在两者之间放置一些组件,这将获取所有消息并将其发布到相关 channel 。

还有其他想法吗?

最佳答案

Salvatore/Redis 的创造者在这里回答了这个问题:https://groups.google.com/forum/#!topic/redis-db/R09u__3Jzfk

All the complexity on the end is on the PUBLISH command, that performs
an amount of work that is proportional to:

a) The number of clients receiving the message.
b) The number of clients subscribed to a pattern, even if they'll not
match the message.

This means that if you have N clients subscribed to 100000 different
channels, everything will be super fast.

If you have instead 10000 clients subscribed to the same channel,
PUBLISH commands against this channel will be slow, and take maybe a
few milliseconds (not sure about the actual time taken). Since we have
to send the same message to everybody.

关于redis - Redis PubSub 订阅机制是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54178462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com