[] Redis redis subscriptions of subscription features

redis of subscriptions

 

Subscribe redis

Redis achieved through subscription and publishing mode PUBLISH, SUBSCRIBE commands.

Example 1:

Notice qq group, a single publisher, multiple listeners

Publish / Subscribe experiment

command

复制代码
PUBLISH channel msg 
    to send information message to the specified channel Channel 

SUBSCRIBE Channel [Channel ...] 
    subscribe to channels, you can subscribe to multiple channels simultaneously 

UNSUBSCRIBE [channel ...] 
    unsubscribe specified channel, if you do not specify a channel, will be canceled subscribe to all channels 
PSUBSCRIBE pattern [pattern ...] 
    subscribe to one or more channels match a given pattern, each pattern as to match the symbol *, it * matches all such channels beginning with it (it.news, it.blog , it.tweets etc.), news. * matches all. channels (news.it, news.global.today etc.), beginning with news like 
PUNSUBSCRIBE [pattern [pattern ...]] 
    unsubscribe specified rules, If there are no parameters will unsubscribe from all the rules 
PUBSUB subcommand [argument [argument ...] ] 
    View subscription and publishing system state 
Note: use publish message queue subscription model to achieve, when the client has subscribed channel can only receive subsequent releases message to the channel, not the cache before sending must Provider and Consumer simultaneously online.
复制代码

Specify which channels to subscribe:

Add the following parameters to solve the Chinese coding problem landing:

redis-cli -p 6380 -h 192.168.61.129 --raw

模糊匹配订阅频道

订阅一个或多个符合的频道

redis订阅

Redis 通过 PUBLISH 、 SUBSCRIBE 等命令实现了订阅与发布模式。

举例1:

qq群的公告,单个发布者,多个收听者

发布/订阅 实验

命令

复制代码
PUBLISH channel msg
    将信息 message 发送到指定的频道 channel

SUBSCRIBE channel [channel ...]
    订阅频道,可以同时订阅多个频道

UNSUBSCRIBE [channel ...]
    取消订阅指定的频道, 如果不指定频道,则会取消订阅所有频道
PSUBSCRIBE pattern [pattern ...]
    订阅一个或多个符合给定模式的频道,每个模式以 * 作为匹配符,比如 it* 匹配所    有以 it 开头的频道( it.news 、 it.blog 、 it.tweets 等等), news.* 匹配所有    以 news. 开头的频道( news.it 、 news.global.today 等等),诸如此类
PUNSUBSCRIBE [pattern [pattern ...]]
    退订指定的规则, 如果没有参数则会退订所有规则
PUBSUB subcommand [argument [argument ...]]
    查看订阅与发布系统状态
注意:使用发布订阅模式实现的消息队列,当有客户端订阅channel后只能收到后续发布到该频道的消息,之前发送的不会缓存,必须Provider和Consumer同时在线。
复制代码

指定订阅哪些频道:

登陆时加下面的参数即可解决中文编码问题:

redis-cli -p 6380 -h 192.168.61.129 --raw

模糊匹配订阅频道

订阅一个或多个符合的频道

Guess you like

Origin www.cnblogs.com/youxiu123/p/11493132.html