众所周知,Java,C++等面向对象有一种常见的设计模式:观察者模式,redis这种机制叫做发布订阅功能.
以下假设已redis经在操作系统中安装成功,
客户端(假设我们客户端叫做A):
(1)redis 127.0.0.1:6379> SUBSCRIBE A
Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "redisChat"3) (integer) 11) "message"2) "redisChat"观察者:(PUBLISH 代表发送消息)
redis 127.0.0.1:6379> PUBLISH A "hello world"
(integer) 1客户端的变化:
Reading messages... (press Ctrl-C to quit)
1) "subscribe"2) "A"3) (integer) 11) "message"2) "A"3) "hello world"