![这里写图片描述](https://img-blog.csdn.net/20170610022718671?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGhld2luZGtlZQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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