Redis(六)发布订阅

Redis(六)发布订阅

进程间的一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息。例如:微信订阅号

订阅一个或多个频道

127.0.0.1:6379> subscribe cctv1 cctv5 vvtv6					#订阅频道
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "cctv1"
3) (integer) 1
1) "subscribe"
2) "cctv5"
3) (integer) 2
1) "subscribe"
2) "vvtv6"
3) (integer) 3
1) "message"
2) "cctv5"
3) "NBA"
1) "message"
2) "cctv1"
3) "news"
127.0.0.1:6379> publish cctv5 NBA							#发送消息
(integer) 1													#成功
127.0.0.1:6379> publish cctv6 superman
(integer) 0													#失败
127.0.0.1:6379> publish cctv1 news
(integer) 1

猜你喜欢

转载自blog.csdn.net/weixin_49741990/article/details/112796971