• Redis发布订阅


    Redis 的 pub sub实现了邮件系统,发送者(在 Redis 术语中被称为发布者)发送的邮件,而接收器(用户)接收它们。由该消息传送的链路被称为信道。

    Redis客户端可以订阅任何数目的通道。

    例子

    以下举例说明如何发布用户的概念工作。在下面的例子给出一个客户端订阅一个通道名为redisChat

    redis 127.0.0.1:6379> SUBSCRIBE redisChat Reading messages… (press Ctrl-C to quit) 1) “subscribe” 2) “redisChat” 3) (integer) 1

    现在,两个客户端都发布在同一个通道名redisChat消息及以上的订阅客户端接收消息。

    redis 127.0.0.1:6379> PUBLISH redisChat “Redis is a great caching technique” (integer) 1 redis 127.0.0.1:6379> PUBLISH redisChat “Learn redis by tutorials point” (integer) 1 1) “message” 2) “redisChat” 3) “Redis is a great caching technique” 1) “message” 2) “redisChat” 3) “Learn redis by tutorials point”

    Redis PubSub 命令

    如下表所示相关Redis PubSub的一些基本的命令:

    S.N.Command & 描述
    1 PSUBSCRIBE pattern [pattern …]
    订阅通道匹配给定的模式。
    2 PUBSUB subcommand [argument [argument …]]
    讲述了PubSub的系统,例如它的客户是活动在服务器上的状态。
    3 PUBLISH channel message
    发布一条消息到通道。
    4 PUNSUBSCRIBE [pattern [pattern …]]
    停止监听发布到通道匹配给定模式的消息。
    5 SUBSCRIBE channel [channel …]
    监听发布到指定的通道信息。
    6 UNSUBSCRIBE [channel [channel …]]
    停止监听发布给定的通道信息。

    PS:如果您想和业内技术大牛交流的话,请加qq群(521249302)或者关注微信公众 号(AskHarries),谢谢!

  • 相关阅读:
    模仿jquery的一些实现
    使按钮失效的方法
    类似jquery的一个demo
    oracle 集合变量以及自定义异常的用法
    java的for循环问题的解决,以及安卓中ListView插入数据的问题
    Spring AOP基于xml配置实例
    plsql 的循环之 goto
    Spring AOP报错
    补全aaz288 可能有问题的过程 P_COMPL_AAZ288
    Spring注解配置
  • 原文地址:https://www.cnblogs.com/kluan/p/6020838.html
Copyright © 2020-2023  润新知