redis发布订阅

这里写图片描述

cli-1:
redis 127.0.0.1:6379> publish channel:sports "Tim won the championship"
(integer) 0
redis 127.0.0.1:6379> publish channel:sports "James lost the championship"
(integer) 1

cli-2在执行了订阅命令后,进入订阅状态,只能接收subscribe、psubscribe、unsubscribe、punsubscribe四个命令。

cli-2:
redis 127.0.0.1:6379> subscribe channel:sports
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel:sports"
3) (integer) 1
1) "message"
2) "channel:sports"
3) "James lost the championship"

取消订阅

redis 127.0.0.1:6379> unsubscribe channel:sports
1) "unsubscribe"
2) "channel:sports"
3) (integer) 0
原文地址:https://www.cnblogs.com/thewindkee/p/12873210.html