0x001 订阅一个或者多个频道

命令格式:SUBSCRIBE channel [channel channel ...]
$ redis-cli
# 进程1
127.0.0.1:6379> SUBSCRIBE chat chat2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "chat"
3) (integer) 1
1) "subscribe"
2) "chat2"
3) (integer) 2

0x002 发布消息

命令格式:PUBLISH channel message
$ redis-cli
# 进程2
127.0.0.1:6379> PUBLISH chat hellochat1
(integer) 1
127.0.0.1:6379> PUBLISH chat2 hellochat2
(integer) 1
#此时的进程1
127.0.0.1:6379> SUBSCRIBE chat chat2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "chat"
3) (integer) 1
1) "subscribe"
2) "chat2"
3) (integer) 2
1) "message"
2) "chat"
3) "hellochat1"
1) "message"
2) "chat2"
3) "hellochat2"
如果觉得我的文章对你有用,请随意赞赏

你可能感兴趣的文章

载入中...
Planets
followWinter followWinter

137 声望

发布于专栏

漫漫填坑路,十里长安响码声。

哎,好像不能申请多个专栏呢,原本这个专栏只放前端文章,现在看来不行了!就都放吧!

3 人关注