zoukankan      html  css  js  c++  java
  • Redis 发布订阅

    Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息。

    Redis 客户端可以订阅任意数量的频道。

    当有新消息通过 PUBLISH 命令发送给频道 channel1 时, 这个消息就会被发送给订阅它的三个客户端:

    redis发布订阅命令
    1.PSUBSCRIBE pattern [pattern ...] 订阅一个或多个符合给定模式的频道。 2.PUBSUB subcommand [argument [argument ...]] 查看订阅与发布系统状态。 3.PUBLISH channel message 将信息发送到指定的频道。 4.PUNSUBSCRIBE [pattern [pattern ...]] 退订所有给定模式的频道。 5.SUBSCRIBE channel [channel ...] 订阅给定的一个或多个频道的信息。 6.UNSUBSCRIBE [channel [channel ...]] 指退订给定的频道。
    ###例子
    1.在当前redis客户端订阅频道名为redisChat
    redis 127.0.0.1:6379> SUBSCRIBE redisChat
    
    2.重新开户个客户端,然后在同一频道redisChat发布再次消息,订阅者就能收到消息
    redis 127.0.0.1:6379> PUBLISH redisChat "Redis is a great caching technique"
    redis 127.0.0.1:6379> PUBLISH redisChat "Learn redis by runoob.com"
    
  • 相关阅读:
    SHELL[22]
    SHELL[15]
    SHELL[08]
    SHELL[12]
    SHELL[06]
    SHELL[24]
    SHELL[11]
    shell文件合并、去重
    SHELL[25]
    SHELL[14]
  • 原文地址:https://www.cnblogs.com/konglingxi/p/9453355.html
Copyright © 2011-2022 走看看