Redis Pub Sub channel memory

此生再无相见时 提交于 2019-12-21 04:12:14

问题


What mechanism(s) does Redis use to keep messages in memory in case of pub-sub ? If no client is subscribed what happens to the messages? Will Redis buffer them ? Is there a way to configure the min. and max. memory allocated per channel ?


回答1:


Redis does not keep messages in memory in the Pub/Sub context as you can see in the implementation (x):

  1. the message is sent to clients listening for that channel (if any),
  2. the message is sent to clients listening to matching channels (if any).

Then Redis simply returns how many clients have received the message (keeping in mind that a client may receive a single message multiple times e.g if multiple pattern matches).

If there is no client subscribed, Redis simply returns 0 and the message is not recorded/buffered:

> publish foo test
(integer) 0

(x) basically Redis loops over the list of subscribed clients and sends a reply with the message.



来源:https://stackoverflow.com/questions/24210754/redis-pub-sub-channel-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!