redis SUBSCRIBE command


  Translation results:

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 SUBSCRIBE commandsyntax

Function:Subscribe to the information of one or more given channels.

Syntax: SUBSCRIBE channel [channel ...]

Available versions: >= 2.0.0

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

Return: The information received.

redis SUBSCRIBE commandexample

# 订阅 msg 和 chat_room 两个频道
# 1 - 6 行是执行 subscribe 之后的反馈信息
# 第 7 - 9 行才是接收到的第一条信息
# 第 10 - 12 行是第二条
redis> subscribe msg chat_room
Reading messages... (press Ctrl-C to quit)
1) "subscribe"       # 返回值的类型:显示订阅成功
2) "msg"             # 订阅的频道名字
3) (integer) 1       # 目前已订阅的频道数量
1) "subscribe"
2) "chat_room"
3) (integer) 2
1) "message"         # 返回值的类型:信息
2) "msg"             # 来源(从那个频道发送过来)
3) "hello moto"      # 信息内容
1) "message"
2) "chat_room"
3) "testing...haha"

Popular Recommendations

Home

Videos

Q&A