博客
关于我
Redis 高级特性(2)—— 发布 订阅模式
阅读量:503 次
发布时间:2019-03-07

本文共 1454 字,大约阅读时间需要 4 分钟。

Redis ???? ?? ????

1. ??-????

??-????????????????????????????????????????channel??????????????????????????????????????????


2. ??-????

????

???????????

publish channel message
  • channel??????????????
  • message??????

????

????????

subscribe channel [channel...]
  • channel?????????????????????????
  • [channel...]???????????????

3. ??-????

??????

?????????????????????????????????

  • subscribe?????????????

    • ???????????????
    • ??????????????????
  • message??????????

    • ???????????????
    • ??????????
  • unsubscribe?????????????????

    • ?????????????
    • ????????????????????? 0 ?????????????

  • ????

    ????

    # ??????? `channel`redis-cli -h 127.0.0.1 publish channel "hello"# ??????? `channel`redis-cli -h 127.0.0.1 publish channel "How are you"

    ????

    # ???? `channel`redis-cli -h 127.0.0.1 subscribe channel

    ????????????????????????

    # ????1) "subscribe"2) "channel"3) (integer) 11) "message"2) "channel"3) "How are you"

    ?????

    ???????????? psubscribe ???????????????

    # ????? `*` ?????redis-cli -h 127.0.0.1 psubscribe greets*

    ??????????????? greets ???????

    # ?????????redis-cli -h 127.0.0.1 publish greet1 "hello"redis-cli -h 127.0.0.1 publish greets_1 "hello"redis-cli -h 127.0.0.1 publish greets_2 "world"redis-cli -h 127.0.0.1 publish greets_3 "I am redis"

    ?????

    # ????1) "psubscribe"2) "greets*"3) (integer) 11) "pmessage"2) "greets*"3) "greets_1"4) "hello"1) "pmessage"2) "greets*"3) "greets_2"4) "world"1) "pmessage"2) "greets*"3) "greets_3"4) "I am redis"

    ?????????????? Redis ??-??????????????

    转载地址:http://njkjz.baihongyu.com/

    你可能感兴趣的文章
    Objective-C实现系统托盘功能(附完整源码)
    查看>>
    Objective-C实现系统时间戳(附完整源码)
    查看>>
    Objective-C实现素数的确定性 Miller-Rabin 算法(附完整源码)
    查看>>
    Objective-C实现累加校验和(附完整源码)
    查看>>
    Objective-C实现红黑树算法(附完整源码)
    查看>>
    Objective-C实现约分(化简比)(附完整源码)
    查看>>
    Objective-C实现约瑟夫环(附完整源码)
    查看>>
    Objective-C实现约瑟夫环算法(附完整源码)
    查看>>
    Objective-C实现约瑟夫问题(附完整源码)
    查看>>
    Objective-C实现线性反馈移位寄存器LFSR(附完整源码)
    查看>>
    Objective-C实现线性查找算法(附完整源码)
    查看>>
    Objective-C实现线程安全的单例模式(附完整源码)
    查看>>
    Objective-C实现线程池(附完整源码)
    查看>>
    Objective-C实现组合模式(附完整源码)
    查看>>
    Objective-C实现绘制跳动的桃心(附完整源码)
    查看>>
    Objective-C实现给定一个 NxN 网格,找出单元格 [0, 0] 中的老鼠是否可以到达单元格 [N-1, N-1] 中的目标算法(附完整源码)
    查看>>
    Objective-C实现给定一个句子,返回出现次数最多的单词算法(附完整源码)
    查看>>
    Objective-C实现给定一个数字数组,返回最大乘积数组中的 3 个数字算法(附完整源码)
    查看>>
    Objective-C实现给定一个整数 n,将最小步数返回到 1算法(附完整源码)
    查看>>
    Objective-C实现给定一串字符,返回出现频率最高的字符算法(附完整源码)
    查看>>