The subscription model Redis

redis The client may subscribe a custom message from the receiving channel

subscription

Subscribe to the specified channel -SUBSCRIBE

SUBSCRIBE channel [channel2]...
SUBSCRIBE 频道名 [频道名2]...

127.0.0.1:6379> subscribe channel1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1

Subscribe to match channel -PSUBSCRIBE

Match mode can subscribe to the channel name in line with the match
PSUBSCRIBE channel*
on behalf of subscribers channelat the beginning of the channel

127.0.0.1:6379> psubscribe channel*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "channel*"
3) (integer) 1

Pattern matching to note that matching names may appear in the future, but who knows which channels will appear, as much as possible not to use this mode, you can not expect a news channel after appear in

release

PUBLISH

PUBLISH channel message
Sending a message to a specific channel

127.0.0.1:6379> publish channel3 "test channel 3"
(integer) 1
127.0.0.1:6379> publish channel1 "test channel 1"
(integer) 3

The return value is the number of clients of the message received

Redis publish-subscribe system should also pay attention to some problems, network transmission problems may be dropped

Guess you like

Origin www.cnblogs.com/liangshu/p/12418880.html