1. PUBLISH channel message
将信息 message 发送到指定的频道 channel 。
起始版本:
2.0.0
时间复杂度:
O(N+M),其中 N 是频道 channel 的订阅者数量,而 M 则是使用模式订阅(subscribed patterns)的客户端的数量。
返回值:
接收到信息 message 的订阅者数量。
案例
# 对没有订阅者的频道发送信息, 返回0
127.0.0.1:6379> PUBLISH channel1 'hello?'
(integer) 0
# 客户端1订阅此频道
127.0.0.1:6379> SUBSCRIBE channel1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1
# 向有一个订阅者的频道发送信息
127.0.0.1:6379> PUBLISH channel1 'hello?'
(integer) 1
# 客户端2再订阅此频道
127.0.0.1:6379> SUBSCRIBE channel1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1
# 向有多个订阅者的频道发送信息
127.0.0.1:6379> PUBLISH channel1 'hello?'
(integer) 2