redis做消息推送的示例:
客戶端A訂閱通道:
redis 127.0.0.1:6379> SUBSCRIBE channeltest
客戶端B往該通道發送消息:
redis 127.0.0.1:6379> PUBLISH channeltest hello(integer) 1
redis 127.0.0.1:6379> PUBLISH channeltest world
(integer) 1
客戶端A就能獲取到推送的信息:
redis 127.0.0.1:6379> SUBSCRIBE channeltestReading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channeltest"
3) (integer) 1
1) "message"
2) "channeltest"
3) "hello"
1) "message"
2) "channeltest"
3) "world"