zoukankan      html  css  js  c++  java
  • ruby如何使用redis订阅/发布

    redis提供的发布订阅命令
    subscribe: subscribe channel [channel …] 订阅一个或多个频道
    unsubscribe: unsubscribe [channel [channel …]] 退订频道,如果没有指定频道,则退订所有的频道
    publish: publish channel message 给指定的频道发消息
    psubscribe: psubscribe pattern [pattern …] 订阅给定模式相匹配的所有频道
    punsubscribe: punsubscribe [pattern [pattern …]] 退订给定的模式,如果没有指定模式,则退订所有模式

    ruby中订阅一个频道test_channel(长连接)

    channel_name = "test_channel"
    
    redis = Redis.current
    redis.subscribe(channel_name) do |on|
        on.message do |channel, message|
            Rails.logger.info("listen #{channel}: #{message}")
        end
    end

    然后在另一个console中redis发布

    redis = Redis.current
    redis.publish('test_channel', 'hello')
  • 相关阅读:
    subtitleedit
    NHibernate.Mapping1.1.csgen 模板
    js jqueryhotkeys
    c#.net将对象序列化,反序列化json
    ruby document
    sqlserver2008新数据类型
    [转]杂记
    UVA 532 Dungeon Master
    UVA 10557 XYZZY
    UVA 10129 Play on Words
  • 原文地址:https://www.cnblogs.com/wangyuyu/p/13261730.html
Copyright © 2011-2022 走看看