Redis-发布订阅
来源:互联网 发布:linux 发送arp包 编辑:程序博客网 时间:2024/06/06 05:02
Redis-发布订阅
一.Redis的发布订阅机制
Redis提供了基于“发布订阅”模式的消息机制,此种模式下,消息发布者和订阅者不进行直接通信,发布者客户端向指定的频道(channel)发布消息,订阅该频道的每个客户都可以收到该消息
二.命令
2.1 发布消息
命令; publish channel message
publish channel1 message2
2.2 订阅消息
Redis客户端可以订阅多个频道的消息
命令:subscribe channel[channel…]
10.3.34.101:6378> subscribe channelchanndl1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel"
3) (integer) 1
1) "subscribe"
2) "channdl1"
3) (integer) 2
1) "message"
2) "channdl1"
3) "message2"
2.3 取消订阅
命令:unsubscribe channel[channel…]
例如:
10.3.34.101:6378> unsubscribe channdl1
1) "unsubscribe"
2) "channdl1"
3) (integer) 0
2.4 按模式订阅
命令:psubscribe patten[pattern…]
例如:
10.3.34.101:6378> psubscribe cha*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "cha*"
3) (integer) 1
1) "pmessage"
2) "cha*"
3) "cha1"
4) "dd"
12.2.4 按模式取消订阅
命令:punsubscribe [patten[pattern…]]
2.5 查看订阅
2.5.1 查看活跃频道
活跃频道是指至少有一个订阅者的频道
命令:pubsub channels[pattern
例如:
10.3.34.101:6378> pubsub channels
1) "channel1"
2.5.2 查看频道订阅数
命令:pubsub numsub [channel…]
例如:
10.3.34.101:6378> pubsub numsub channel1
1) "channel1"
2) (integer) 2
2.5.3 查看模式订阅数
命令:pubsub numpat
例如:
客户端1:
10.3.34.101:6378> psubscribe pcha
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "pcha"
3) (integer) 1
客户端2:
10.3.34.101:6378> psubscribe pcha
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "pcha"
3) (integer) 1
客户端3:
10.3.34.101:6378> pubsub numpat
(integer) 2
三. 应用场景
聊天室,公告牌,服务之间利用消息解耦都可以使用发布订阅模式
- 六.redis 发布订阅
- Redis:六、发布、订阅
- .redis 发布订阅
- 六.redis 发布订阅
- Redis:六、发布、订阅
- redis代码 发布订阅
- Redis 发布与订阅
- redis发布和订阅
- Redis 发布订阅
- Redis 发布与订阅
- Redis 订阅与发布
- Redis 发布与订阅
- redis实现发布/订阅
- Redis发布订阅模式
- redis 订阅 发布
- Redis 发布订阅
- Redis-发布与订阅
- redis订阅和发布
- python的对象
- WebSocket实现Android客户端之间的简单通讯
- @Table
- qml与C++的交互
- IntelliJ IDEA设置自动导入包
- Redis-发布订阅
- Unity Build exe 设置默认分辨率
- HashMap,LinkedHashMap,TreeMap的区别
- App:transformClassesWithDexForDebug
- servlet练习(1)
- View小知识
- @Id
- 设计模式(二十)visitor访问器
- nodejs中server.close()的使用