在redis消息总线中为每个用户创建一个频道是一种好习惯吗?

时间:2019-02-21 09:51:18

标签: redis message-queue stackexchange.redis azure-redis-cache message-bus

我们正在使用Redis消息总线,并使用通道来处理消息。但是,如果我们的应用程序部署在多个实例中,那么请求和响应将传递到所有实例。为了避免这种情况,以下哪种方法更好?

  1. 为应用程序的每个实例创建一个通道
  2. 为每个用户创建一个频道

任何建议都会受到赞赏

1 个答案:

答案 0 :(得分:0)

此处的限制因素是同一频道的订户数量。这样,通道数可能会很大。因此,您可以相应地选择粒度。在此处阅读更多信息:

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.

之前问过类似的问题:How does Redis PubSub subscribe mechanism works?