subscribe

UK[s?b?skra?b] US[s?b?skra?b]

vt.& vi. Subscription; pledge, donation; signature, inscription, signature; subscription, Order

Third person singular: subscribes Present participle: subscribing Past tense: subscribed Past participle: subscribed

redis PSUBSCRIBE command syntax

Function:Subscribe to one or more channels that match the given pattern.

Syntax: PSUBSCRIBE pattern [pattern ...]

Description: Each pattern uses * as the matching character, for example, it* matches all Channels that start with it ( it.news , it.blog , it.tweets , etc.), news.* matches all channels that start with news. ( news.it , news.global.today , etc.), and so on.

Available versions: >= 2.0.0

Time complexity: O(N), N is the number of subscribed patterns.

Returns: The information received (see code description below).

redis PSUBSCRIBE command example

# 訂閱 news.* 和 tweet.* 兩個(gè)模式
# 第 1 - 6 行是執(zhí)行 psubscribe 之后的反饋信息
# 第 7 - 10 才是接收到的第一條信息
# 第 11 - 14 是第二條
# 以此類推。。。
redis> psubscribe news.* tweet.*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"                  # 返回值的類型:顯示訂閱成功
2) "news.*"                      # 訂閱的模式
3) (integer) 1                   # 目前已訂閱的模式的數(shù)量
1) "psubscribe"
2) "tweet.*"
3) (integer) 2
1) "pmessage"                    # 返回值的類型:信息
2) "news.*"                      # 信息匹配的模式
3) "news.it"                     # 信息本身的目標(biāo)頻道
4) "Google buy Motorola"         # 信息的內(nèi)容
1) "pmessage"
2) "tweet.*"
3) "tweet.huangz"
4) "hello"
1) "pmessage"
2) "tweet.*"
3) "tweet.joe"
4) "@huangz morning"
1) "pmessage"
2) "news.*"
3) "news.life"
4) "An apple a day, keep doctors away"