redis的发布订阅

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"

 

转载于:https://www.cnblogs.com/mxf97826/p/8707962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值