Redis之发布与订阅
发布订阅
进程间的一种消息通信模式:发布者发送消息,订阅者接收消息
订阅者接收消息 一次性订阅多个
1 127.0.0.1:6379> SUBSCRIBE c1 c2 c3 2 Reading messages... (press Ctrl-C to quit) 3 1) "subscribe" 4 2) "c1" 5 3) (integer) 1 6 1) "subscribe" 7 2) "c2" 8 3) (integer) 2 9 1) "subscribe" 10 2) "c3" 11 3) (integer) 3 12 1) "message" 13 2) "c2" 14 3) "woshiniba" 15 1) "message" 16 2) "c1" 17 3) "woshinidie" 18 # -----------------------------通配符*------------------- 19 127.0.0.1:6379> PSUBSCRIBE new* 20 Reading messages... (press Ctrl-C to quit) 21 1) "psubscribe" 22 2) "new*" 23 3) (integer) 1 24 1) "pmessage" 25 2) "new*" 26 3) "new13" 27 4) "nishishabi" 28 29 # 发布者发送消息 30 127.0.0.1:6379> PUBLISH c2 woshiniba 31 (integer) 1 32 127.0.0.1:6379> PUBLISH c1 woshinidie 33 (integer) 1 34 # -----------------------通配符-------------------------- 35 127.0.0.1:6379> PUBLISH new13 nishishabi 36 (integer) 1