psubscribe 命令

psubscribe 命令订阅一个或多个符合给定模式的频道。每个模式以 * 作为匹配符,比如 it* 匹配所有以 it 开头的频道(it.news 、 it.blog 、 it.tweets 等等)。 news.* 匹配所有以 news.开头的频道(news.it 、 news.global.today 等等),诸如此类。特殊字符使用 \ 转义。

语法

PSUBSCRIBE pattern[pattern ...]

返回值

接收到的信息。

实例

redis> PSUBSCRIBE new.*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "new.*"
3) (integer) 1

1) "pmessage"
2) "new.*"      # 消息匹配的模式
3) "new.one"    # 消息本身的目标频道
4) "Hi"
redis> PSUBSCRIBE mychannel
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "mychannel"
3) (integer) 1