4 Redis的发布订阅
生活随笔
收集整理的這篇文章主要介紹了
4 Redis的发布订阅
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Redis 的發(fā)布訂閱(pub/sub)是一種消息通信模式:發(fā)送者(pub)發(fā)送消息,訂閱者(sub)接收消息
Redis 客戶端可以訂閱任意數(shù)量的頻道。
先訂閱后發(fā)布才能收到消息
1 打開一個(gè)客戶端訂閱channel1
[chengwen@localhost redis]$ redis-server /etc/redis.conf [chengwen@localhost redis]$ redis-cli 127.0.0.1:6379> subscribe channel1 Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "channel1" 3) (integer) 12 打開另一個(gè)客戶端給chanel1 發(fā)布消息hello redis
[chengwen@localhost redis]$ redis-cli 127.0.0.1:6379> publish channel1 "hello redis" (integer) 1 127.0.0.1:6379>3 回看第一個(gè)客戶端消息變?yōu)?/h3> [chengwen@localhost redis]$ redis-server /etc/redis.conf [chengwen@localhost redis]$ redis-cli 127.0.0.1:6379> subscribe channel1 Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "channel1" 3) (integer) 1 1) "message" 2) "channel1" 3) "hello redis"
增加了如下消息
1) "message" 2) "channel1" 3) "hello redis"總結(jié)
以上是生活随笔為你收集整理的4 Redis的发布订阅的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3 Redis 配置文件
- 下一篇: 7 Redis 事务