欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Redis实现订阅发布

程序员文章站 2022-07-05 10:35:05
...

Redis实现订阅发布

subscribe channel[channel…]
订阅给定的一个或多个频道的信息

127.0.0.1:6379> SUBSCRIBE maple # 订阅
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "maple"
3) (integer) 1
# 等待读取推送的消息
1) "message"
2) "maple" # 来自哪个频道的消息
3) "hello maple" # 消息内容
1) "message"
2) "maple"
3) "hello redis"

publish channel message
将信息发送到指定频道

127.0.0.1:6379> PUBLISH maple "hello maple" # 发布者发布消息到频道
(integer) 1
127.0.0.1:6379> publish maple "hello redis"
(integer) 1

使用subscribe订阅一个频道,publish发送一个消息,可以看到如上效果。

unsubscribe channel[channel…]
退订给定的频道

等等,看完得捋一捋~

相关标签: Redis redis