Hello!
2015-01-15 6:08 GMT-08:00 Penguin:
> 你好 有问题想请教 目前想用nginx+redis,但不知道怎么使用redis的高可用,所以想法是使用lua创建连接池,用的是redis.lua,
> 想用lua监听sentinel的switch-master频道,但一旦监听就变成了阻塞的,无法继续运行,请问有好的思路吗?比如另开一个lua程序,
可以使用 ngx.timer.at [1] 创建的循环定时器来运行 nginx 内部的"后台轻量级线程"来做这样的“背景监控”。定时器可以由
init_worker_by_lua 发起。具体实现可以参考 lua-resty-upstream-healthcheck 库 [2]。
另外,下面这个针对 lua-resty-redis 的 pull request 也值得参考:
https://github.com/openresty/lua-resty-redis/pull/49/files?short_path=0a36949
Regards,
-agentzh
[1] https://github.com/openresty/lua-nginx-module#ngxtimerat
[2] https://github.com/openresty/lua-resty-upstream-healthcheck