redis发布订阅模式-redis系列教程
来源:互联网 发布:上海聚宝网络 编辑:程序博客网 时间:2024/06/06 09:54
介绍
redis的发布订阅模式可以实现进程间的消息传递
命令
publish channel message
往指定频道发送消息,如果频道不存在则发送失败,一定要有客户端订阅你发送的频道。subscribe channel [channel ...]
订阅一个或多个频道,只有先订阅才能发送消息psubscribe pattern [pattern ...]
访问一个或多个频道,支持glob风格的通配符unsubscribe [channel [channel ...]]
取消一个或多个订阅,如果不指定频道表示取消所有subscribe命令的订阅punsubscribe [pattern [pattern ...]]
取消一个或多个订阅,如果不指定频道表示取消所有psubscribe命令的订阅。
示例
同时开启两个客户端,分别模拟订阅者和发布者。
subscribe
127.0.0.1:6379> subscribe s1Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "s1"3) (integer) 1
此时订阅这边会一直等待
publish
我们订阅s1频道并往里面发送一条消息
127.0.0.1:6379> publish s1 hello(integer) 1
如果返回1表示成功,返回0表示失败
结果
当上面的命令发送成功之后,在订阅者这边可以收到消息。
127.0.0.1:6379> subscribe s1Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "s1"3) (integer) 11) "message"2) "s1"3) "hello"
阅读全文
1 0
- redis发布订阅模式-redis系列教程
- Redis发布订阅模式
- redis订阅发布模式
- redis-发布、订阅模式
- redis 发布/订阅模式
- Redis发布/订阅模式
- redis发布订阅模式
- Redis教程(九) Redis发布与订阅
- Redis教程(九) Redis发布与订阅
- redis的发布/订阅模式
- Redis发布与订阅模式
- Redis系列~发布订阅(十一)
- Redis——发布订阅模式&虚拟内存
- Redis——发布订阅模式&虚拟内存
- redis 消息队列 发布、订阅模式
- 【Redis系列】Redis频道发布与消息订阅
- Redis系列(三):Redis发布订阅及客户端编程
- Redis系列(三)-Redis发布订阅及客户端编程
- HDU 1494 跑跑卡丁车
- 学习日志2017-7-8
- emacs verilog-mode对IC顶层集成的帮助
- spring技术内幕笔记:IoC容器初始化过程(1)- Resource定位
- 网络基础 — CRC校验的认识以及校验原理
- redis发布订阅模式-redis系列教程
- ps学习笔记(一)
- STL之仿函数
- POJ 3601 Subsequence
- 【Linux服务器配置】服务器的配置
- 实践三
- opencv特征检测与匹配
- 【CSS】选择大图中的小图片效果
- 实验吧 CTF