The Redis list data structure has blpop and brpop commands that can be returned from the table and delete the first (or last) element, or be blocked until an element is available for operation. This can be used to implement a simple queue.
For blpop and brpop commands, if there are no keywords in the list to manipulate, the connection will be blocked until another Redis client uses lpush or commands to push the rpush keyword. )
In addition, Redis has first-class support for message publishing and channel subscriptions. You can open a second redis-cli window and try these features. Subscribe to a channel in the first window (we'll call it warnings ):
subscribe warnings
It will reply to the information you have subscribed to. Now, in another window, publish a message to the warnings channel:
publish warnings "it‘s over 9000!"
If you go back to the first window, you should have received warnings a message from the channel.
You can subscribe to multiple channels ( subscribe channel1 channel2 ... ), subscribe to a set of mode-based channels ( psubscribe warnings:* ), and use unsubscribe and punsubscribe command stop listening on one or more channels, or a channel mode.
Finally, you can notice that publish the return value of the command is 1, which indicates the number of clients that received the message .
Here the client and server side with a long connection to establish a push mechanism, a client to publish messages, you can receive notifications on multiple clients.
Reference:
Http://redis.io/topics/pubsub Chinese Translation: http://www.redis.cn/topics/pubsub.html
Https://redis.readthedocs.org/en/latest/pub_sub/index.html