Redis学习笔记四(发布订阅)

1. 发布订阅

  1. 发布订阅是一种消息通信模式,发布者发送消息,订阅者接收消息
  2. redis客户端可以订阅任意数量的频道(一个发布者可以有多个发布频道)
    image
    image

2. 实现

  1. 订阅频道 subscribe <channel>
127.0.0.1:6379> subscribe channel1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1
  1. 发布数据到频道publish <channel> <数据>
127.0.0.1:6379> publish channel1 hello
(integer) 1
  1. 查看
127.0.0.1:6379> subscribe channel1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1
1) "message"
2) "channel1"
3) "hello"
posted @ 2022-06-19 17:33  小懒虫LK  阅读(53)  评论(0)    收藏  举报