[Redis-CentOS7]Redis发布订阅操作(七)

发布订阅

  • 发布:打电话
  • 订阅:接电话

订阅频道

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

发布信息

127.0.0.1:6379> multi
OK
127.0.0.1:6379> PUBLISH msg "A"
QUEUED
127.0.0.1:6379> PUBLISH msg "B"
QUEUED
127.0.0.1:6379> PUBLISH msg "C"
QUEUED
127.0.0.1:6379> EXEC
1) (integer) 1
2) (integer) 1
3) (integer) 1

接收到订阅

1) "message"
2) "msg"
3) "A"
1) "message"
2) "msg"
3) "B"
1) "message"
2) "msg"
3) "C"

参考网站: http://redisdoc.com/pubsub/index.html

posted @ 2020-02-16 19:19  LeoShi2020  阅读(273)  评论(0编辑  收藏  举报