Redis发布订阅使用方法
发布时间:2020-12-16 04:35:53 所属栏目:安全 来源:网络整理
导读:Redis发布订阅 发布订阅模式中发布消息的为publisher即发布者,接收消息的为subscriber即订阅者。在Redis中,所有的消息通过channel即频道进行发布,一个发布者可以向多个channel发布消息,一个订阅者也可以订阅多个channel。Redis不对消息进行持久化,如果
Redis发布订阅发布订阅模式中发布消息的为publisher即发布者,接收消息的为subscriber即订阅者。在Redis中,所有的消息通过channel即频道进行发布,一个发布者可以向多个channel发布消息,一个订阅者也可以订阅多个channel。Redis不对消息进行持久化,如果消息发布时订阅者还没有进行订阅,则不会再收到此消息。 ? 发布订阅命令
? subscribe不能重复订阅同一个channel,而psubscribe按照匹配模式订阅时有可能会多次订阅同一个channel。如果psubscribe多次订阅了同一个channel,发布者使用publish发布消息到此channel后,订阅者会多次收到此消息。 unsubscribe只能退订subscribe订阅的channel,punsubscribe只能退订psubscribe订阅的channel。 ? 使用方法? 1、订阅指定channel 192.168.1.100:6379> subscribe testchan
Reading messages... (press Ctrl-C to quit)
1) "subscribe" #订阅成功
2) "testchan" #订阅的channel名称
3) (integer) 1 #已订阅的channel个数
1) "message" #收到消息
2) "testchan" #消息来源channel
3) "hello" #消息内容
192.168.1.100:6379> publish testchan hello
(integer) 1 #收到消息的订阅者的数量
2、订阅指定匹配模式的channel 192.168.1.100:6379> psubscribe test*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe" #订阅成功
2) "test*" #订阅的channel匹配模式
3) (integer) 1 #已订阅的channel匹配模式个数
1) "pmessage" #收到消息
2) "test*" #匹配的订阅模式
3) "testchan" #消息来源channel
4) "hello" #消息内容
192.168.1.100:6379> publish testchan hello
(integer) 1 #收到消息的订阅者的数量
原文地址:http://caiguoqing.org/post/110 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 使用AngularJS上的nd-repeat创建代表未来20年的数字的下拉菜
- scala – 从Any到AnyRef的通用/通用拳击
- 老男孩教育每日一题-第95天-shell脚本知识点:书写脚本完成
- Scala中字符串中唯一字符的计数
- 使用axis创建调用 wsdl 形式的 webservice的方法
- .net Remoting、WebService和WCF的区别联系:
- 【实验报告】《数据结构》实验一: VC编程工具的灵活使用
- widget实现forceStop后可以使用的思路
- angularjs – 在控制器而不是视图中访问Angular route scop
- scala – Play Framework 2.0多个静态路由