Redis发布及订阅消息(pub/sub)

发布及订阅消息(pub/sub) 类似观察者模式(web聊天系统)
http://hi.baidu.com/576699909/item/70e306093a6441dadde5b09d
http://www.redis.cn/topics/pubsub.html


session1 
subscribe tv1 --监听tv1
127.0.0.1:6379> subscribe tv1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1


session2
subscribe tv1 tv2 --监听tv1 tv2
127.0.0.1:6379> subscribe tv1 tv2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
1) "subscribe"
2) "tv2"
3) (integer) 2


session3 
publish tv1 d  --通过publish tv1 广播一个信息

session1  session2会立刻接收到
1) "message"
2) "tv1"
3) "dingsai"

publish tv2 dingsaitv2 --通过publish tv2 广播一个信息









你可能感兴趣的:(Redis发布及订阅消息(pub/sub))