redis的发布订阅
是进程间的一种消息通信模式:发送者发送消息,订阅者接收消息。
命令:
SUBSCRIBE:订阅给定的一个或者多个频道信息
PUBLISH:将消息发送到指定的频道
127.0.0.1:6379> SUBSCRIBE c1 c2 c3
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "c1"
3) (integer) 1
1) "subscribe"
2) "c2"
3) (integer) 2
1) "subscribe"
2) "c3"
3) (integer) 3
1) "message" 127.0.0.1:6379> PUBLISH c2 hello-redis
2) "c2" (integer) 1
3) "hello-redis"
1) "message" 127.0.0.1:6379> PUBLISH c1 pika
2) "c1" (integer) 1
3) "pika"
订阅多个:PSUBSCRIBE new*
127.0.0.1:6379> PSUBSCRIBE new*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "new*"
3) (integer) 1
收取消息:PUBLISH new13 redis2015
127.0.0.1:6379> PUBLISH new1 redis2015 1) "pmessage"
2) "new*"
3) "new1"
4) "redis2015"
127.0.0.1:6379> PUBLISH new13 redis2015
1) "pmessage"
2) "new*"
(integer) 1 3) "new13"
4) "redis2015"