Soumya Simanta
Soumya Simanta

Reputation: 11741

Redis Pub Sub channel memory

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 ?

Upvotes: 10

Views: 4126

Answers (1)

deltheil
deltheil

Reputation: 16121

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.

Upvotes: 16

Related Questions