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

    1、什么是Redis发布订阅

      进程间的一种消息通信模式:发送者(Pub)发布信息,订阅者(Sub)接受信息。

    2、案例  

    案例1:一次订阅多个  SUBSCRIBE c1 c2 c3

    消息发布  c2 hello-c2

    127.0.0.1:6379> SUBSCRIBE c1 c2 c3
    Reading messages... (press Ctrl-C to quit)
    1) "subscribe"
    2) "c1"
    3) (integer) 1
    1) "subscribe"
    2) "c2"
    3) (integer) 2
    1) "subscribe"
    2) "c3"
    3) (integer) 3
    1) "message"
    2) "c2"
    3) "hello-c2"
    1) "message"
    2) "c1"
    3) "hello-c1"
    127.0.0.1:6379> PUBLISH c2 hello-c2
    (integer) 1
    127.0.0.1:6379> PUBLISH c1 hello-c1
    (integer) 1

    案例2:订阅多个,通配符* 形式订阅多个   。PSUBSCRIBE new*

    发布信息 PUBLISH new1 redis2019

    127.0.0.1:6379> PSUBSCRIBE new*
    Reading messages... (press Ctrl-C to quit)
    1) "psubscribe"
    2) "new*"
    3) (integer) 1
    1) "pmessage"
    2) "new*"
    3) "new1"
    4) "redis2019"
    1) "pmessage"
    2) "new*"
    3) "new31"
    4) "redis2019"
    127.0.0.1:6379> PUBLISH new1 redis2019
    (integer) 1
    127.0.0.1:6379> PUBLISH new31 redis2019
    (integer) 1

      

  • 相关阅读:
    Codeforces Round #579 (Div. 3)
    2019牛客暑期多校训练营(第一场)ABBA
    Comet OJ
    Codeforces Round #562 (Div. 2)
    Codeforces Round #569 (Div. 2)
    寒假集训总结
    线段树做题总结
    Git学习
    unity开发vuforia血的教训
    (学习13)最短圆排列问题
  • 原文地址:https://www.cnblogs.com/karrya/p/11279255.html
Copyright © 2011-2022 走看看