Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 765
Soumya Simanta Avatar asked Jun 13 '14 17:06

Soumya Simanta


People also ask

Is redis good for pub sub?

Aside from data storage, Redis can be used as a Publisher/Subscriber platform. In this pattern, publishers can issue messages to any number of subscribers on a channel. These messages are fire-and-forget, in that if a message is published and no subscribers exists, the message evaporates and cannot be recovered.

What is redis Pub/Sub channel?

Redis Pub/Sub is the oldest style of messaging pattern supported by Redis and uses a data type called a “channel,” which supports typical pub/sub operations, such as publish and subscribe. It's considered loosely coupled because publishers and subscribers don't know about each other.

How does redis Pub/Sub works?

Redis and PHP Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel. In Redis, a client can subscribe any number of channels.

How many subscribers can redis handle?

Maximum Concurrent Connected Clients In Redis 2.6 and newer, this limit is dynamic: by default it is set to 10000 clients, unless otherwise stated by the maxclients directive in redis.


1 Answers

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.

like image 90
deltheil Avatar answered Dec 19 '22 01:12

deltheil