大家好!
lua-resty-redis 中如何使用 redis 的Pub/Sub(发布/订阅)功能?请有经验哥们介绍一下,谢谢!
Richard Chen
大家好! lua-resty-redis 中如何使用 redis 的Pub/Sub(发布/订阅)功能?请有经验哥们介绍一下,谢谢! Richard Chen --
可以参考:https://github.com/agentzh/lua-resty-redis#read_reply 文档贴一段简单的测试代码: location /redis-sub { content_by_lua ' local cjson = require "cjson" local redis = require "resty.redis" local red = redis:new() red:connect("127.0.0.1", 6379) local res, err = red:subscribe("dog") ngx.say(cjson.encode(res)) res, err = red:read_reply() ngx.say(cjson.encode(res)) '; }用curl访问一下:$ curl http://localhost:8080/redis-sub这里省略一些判断错误的逻辑,在客户端里:$ redis-cliredis 127.0.0.1:6379> PUBLISH dog aaaa 就会看到curl返回输出了。--smallfish http://chenxiaoyu.org On Fri, Nov 29, 2013 at 6:27 PM, Chen Richard <richa...@zkteco.com> wrote: 大家好! lua-resty-redis 中如何使用 redis 的Pub/Sub(发布/订阅)功能?请有经验哥们介绍一下,谢谢! Richard Chen -- class="HOEnZb"> --
大家好! lua-resty-redis 中如何使用 redis 的Pub/Sub(发布/订阅)功能?请有经验哥们介绍一下,谢谢! Richard Chen -- class="HOEnZb">