zoukankan      html  css  js  c++  java
  • 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),谢谢!

  • 相关阅读:
    一次完整的HTTP事务的过程
    移动端事件
    canvas 在视频中的用法
    理解Vue
    改变console.log的输出样式
    百度下拉搜索案例
    Vue总结
    字符串、正则
    .Net Mvc框架知识点
    Lowest Common Ancestor of a Binary Tree -- LeetCode
  • 原文地址:https://www.cnblogs.com/kluan/p/6020838.html
Copyright © 2011-2022 走看看