publish 命令

Publish 命令用于将信息发送到指定的频道。

语法

PUBLISH channel message

返回值

接收到信息的订阅者数量。

实例

redis> PUBLISH mychannel "hello, i m here"
(integer) 1
# 对没有订阅者的频道发送信息
redis> publish bad_channel "can any body hear me?"
(integer) 0


# 向有一个订阅者的频道发送信息
redis> publish msg "good morning"
(integer) 1


# 向有多个订阅者的频道发送信息
redis> publish chat_room "hello~ everyone"
(integer) 3