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 transmitted by this message is called a channel.
Redis clients can subscribe to any number of channels.
Example
The following example shows how to publish a user's conceptual work. In the following example, a client subscription is given a channel named Redischat
Redis 127.0.0.1:6379> SUBSCRIBE redischatreading messages ... (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> PUBLISH redischat "Redis is a great Caching technique" (integer) 1redis 127.0.0.1:6379> PUBLISH Redischat "Learn Redis by Tutorials Point" (integer) One) "message" 2) "Redischat" 3) "Redis is a great caching 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, such as its customer status on the server. |
3 |
PUBLISH Channel Message Publishes a message to the channel. |
4 |
Punsubscribe [pattern [pattern ...]] Stops listening for messages that are published to the channel to match a given pattern. |
5 |
SUBSCRIBE Channel [Channel ...] The listener is published to the specified channel information. |
6 |
unsubscribe [Channel [channel ...]] Stops the listener from publishing the given channel information. |
Article reprinted from: Yi Hundred tutorials [http:/www.yiibai.com]
Article title: Redis Publish Subscription
This address: http://www.yiibai.com/redis/redis_pub_sub.html
Redis Publish Subscriptions