The pub sub of Redis implements mail systems, messages sent by senders (known as publishers in Redis terminology), and receivers (users) receiving them. The link is referred to by the message and is called a channel.
Redis clients can subscribe to any number of channels.
Example
The following is an example of how to publish a user's concept work. In the following example, a client subscription is given a channel named Redischat
Redis 127.0.0.1:6379> SUBSCRIBE Redischat
Reading message ... (Press Ctrl-c to quit)
1) "Subscribe"
2) "Redischat"
3) (integer) 1
Now, two clients are published in the same channel name Redischat message and above the subscribing client receives the message.
Redis 127.0.0.1:6379> pblish redischat "Redis is a great caching technique"
(integer) 1
Redis 127.0.0.1:6379> PUBLISH redischat "Learn Redis by Tutorials Point"
(integer) 1
1) "Message"
2) "Redischat"
3) "Redis is a great cacheing technique"
1) "Message"
2) "Redischat" "
3) "Learn Redis by Tutorials Point"
Redis PubSub Command
Some basic commands related to Redis PubSub are shown in the following table:
S.N. |
Command & Description |
1 |
Psubscribe pattern [pattern ...] The subscription channel matches the given pattern |
2 |
PUBSUB subcommand [argument [argument ...] Describes the PubSub system, for example, its customer is active on the server state |
3 |
PUBLISH Channel Message Publish a message to the channel |
4 |
Pubsubscribe [pattern [pattern ...]] Stop listening for messages that do not send a channel to match a given pattern |
5 |
SUBSCRIBE Channel [Channel ...] Listens to the specified channel information |
6 |
unsubscribe [Channel [channel ...]] Stop listening to publish a given channel information |
Redis QuickStart-Redis Publish subscriptions (12)