< Span style= "color: #000000;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" >9}
When there are multiple consumers, it dispatches the message in the order in which the brpop is called, not randomly. Block_timeout is not recommended for infinity (some Redis drivers also directly do not support inifinity), we are currently set to 30 (units in seconds) in good condition.
Second,pub/sub Mode
Redis supports pub/sub instructions starting from version 2.0.0. For details, see: Http://redis.io/topics/pubsub
Realization idea: Publisher calls Redis's Publish method to send a message to a specific channel, subscriber subscribe to the channel at initialization, and receives the message as soon as it is available.
A relatively simple demo can be found in: http://shift-alt-ctrl.iteye.com/blog/1867454
1. Publication and subscription of REDIS messages
The Redis Subscribe command allows the client to subscribe to any number of channels, and whenever new information is sent to the subscribed channel, the information is sent to all clients subscribed to the specified channel. As an example, it shows the channel CHANNE11 and the three clients subscribing to the channel: Client2, CLIENT5, and client1 relationships:
When a new message is sent to channel Channe11 via the Publish command, the message is sent to the three clients subscribed to it:
Subscribe to the Bar channel. format: Subscribe name1 name2
A successful subscription response, corresponding to the subscription type, subscription channel, number of subscriptions.
127.0.0.1:6379> SUBSCRIBE barreading messages ... (Press Ctrl-C to quit)"subscribe""bar"1
Restart a Publisher client to send a message. format: Publish ChannelName Message
#对有一个订阅者的频道发送信息
127.0.0.1:6379>1
#对没有订阅者的频道发送信息
127.0.0.1:6379> Publish bar "Can any body hear me?"
(integer) 0
Subscribe to the client reply, corresponding to the message type, channel, message.
"message""bar""val "
For details, see: http://www.cnblogs.com/mushroom/p/4470006.html
Http://redis.readthedocs.org/en/2.4/pub_sub.html
2 , key space notification (Keyspace notifications)
before subscribing to a channel, set the set notify-keyspace-events Kea parameter before running the Subscribe name1 name2 subscription channel.
At this point, a message is sent to the subscriber when a specified key is updated
See also: http://redis.io/topics/notifications
http://blog.csdn.net/chaijunkun/article/details/27361453
Redis Message Queuing