1 Introduction
Redis publish-subscribe (pub / sub) is a messaging mode of communication. Sender (Pub) sends a message, the subscriber (Sub) receiving a message
Redis client may subscribe to any number of channels
2. Example
The following shows three channels channel1 client and subscribe to this channel ---- relationship between client2, client5 and client1:
When a message is sent through the channel 1 channel PUBLISH command, this message will be sent to subscribe to it three clients.
3. Command
Subscriptions
subscribe channel [channel...] #订阅给定的一个或多个频道的消息
psubscribe pattern [pattern....] # 订阅一个或多个给定模式的频道
Release channel
publish channel message #将信息发送到指定的频道
Unsubscribe Channel
unsubscribe [channel [channel...]] #指退订给定的频道
punsubscribe [pattern [pattern]] #退订所有给定模式的频道
Code Example 4
[1] first three windows simultaneously open (wherein two analog subscribers, a publisher analog)
[2] The first channel operates in two subscribers subscribe windows
suscribe CCTV5
[. 3] in the third window perform post operation (FIG. 2 represents two Integer received subscriber information)
publish CCTV5 the NBA
[. 4] This two subscribers will also receive information when (then three windows)
Subscribe to the window display interface
The application scenario
The most obvious use of this feature is to build real-time messaging systems, such as ordinary instant messaging, group chat and other functions
[1] In a blog site, there are 100 fans subscribed to you, when you publish a new post, you can push message to the fans.
[2] The micro-channel public number mode