zoukankan      html  css  js  c++  java
  • redis:消息发布与订阅频道

    1. 发布与订阅频道

    消息发布与订阅像收音机与广播台的关系

    1.1. publish channel message 发布频道

    语法:publish channel message

    作用:发布频道消息

    返回值:订阅数(类似粉丝数)

    例:

    127.0.0.1:6379> publish news 'today is sunday'

    (integer) 0

    1.2. subscribe channel [channel ...] 订阅频道

    语法:subscribe channel [channel ...]

    作用:订阅频道

    例:

    窗口1

    127.0.0.1:6379> publish news 'today is sunday'

    (integer) 0

    窗口2

    127.0.0.1:6379> subscribe news

    Reading messages... (press Ctrl-C to quit)

    1) "subscribe"

    2) "news"

    3) (integer) 1

    此时看不到窗口1已经发过的消息,需要再发新消息才能看到

    窗口1:(再发)

    127.0.0.1:6379> publish news 'still sunday'

    (integer) 1

    窗口2:(收到)

    1) "message"

    2) "news"

    3) "still sunday"

    如果再开几个客户端,同样也能收到消息

    1.3. psubscribe pattern [pattern ...] 订阅频道

    语法:psubscribe pattern [pattern ...]

    作用:可以通过匹配模式来一次性订阅多个频道

    例:

    127.0.0.1:6379> psubscribe news*

    Reading messages... (press Ctrl-C to quit)

    1) "psubscribe"

    2) "news*"

    3) (integer) 1

  • 相关阅读:
    app分析报告试验
    NABCD模式试验
    课堂练习
    学生管理系统测试计划及测试矩阵
    图书管理系统活动,时序图
    图书借阅测试用例UML图
    风险分析
    需求规格说明说
    PM的定义跟功能说明模块
    需求分析-NABCD
  • 原文地址:https://www.cnblogs.com/reyinever/p/10041269.html
Copyright © 2011-2022 走看看