Redis has publish/subscribe for sending messages. This is handled by subscribing to a channel & publishing to channel. Yes, subscribers will subscribe to one or more channels. Publisher need not know who are all subscribers. Instead, publisher will publish to specific channel. All the subscribers who are subscribed for that channel will get the message. This decoupling of publishers and subscribers can allow for greater scalability and a more dynamic network topology.
Example: User is subscribing to 2 channels say foo & boo
SUBSCRIBE foo boo
In console of redis-client1:
127.0.0.1:6379> SUBSCRIBE foo boo
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "foo"
3) (integer) 1
1) "subscribe"
2) "boo"
3) (integer) 2
It will start to listen for message. On publish will get data for corresponding channel.
For example: When want to send message to all subscribers who are connected with boo, need to publish to that channel.
PUBLISH boo "Hello Boo"
In console of redis-client1:
1) "message"
2) "boo" //channel name
3) "Hello Boo" //Actual data
To unsubscribe from channel at any point, use
UNSUBSCRIBE // to unsubscribe from all channels
UNSUBSCRIBE foo // to unsubscribe from specific channel
Can do subscribe based on pattern too. When the channel name is not sure/want to subscribe based on pattern use PSUBSCRIBE.
Similarly to unsubscribe based on pattern use PUNSUBSCRIBE