如何关掉 redis 里的 timeout

85 views
Skip to first unread message

葛云飞

unread,
Dec 11, 2018, 7:59:34 AM12/11/18
to openresty

hi,各位
我们现在有一个应用场景,需要订阅 redis 的广播,目前已经实现了,用的是类似于:
         local ok,err = red:subscribe(key,guid())
        if not ok then
            return err
        end
        local flag = true
        while flag do
            local res,err = red:read_reply()
            if err then
                ;
            else
                if res[1] == "message" then
                    local obj = cjson.decode(res[3])
                    flag = func(obj.msg)
                end
            end
       end
这种形式,目前看功能上是 OK 的,但是有一个问题,就err-log 里一直会报 tcp 超时错误,请如如何可以将关掉

老拐瘦&拐爷

unread,
Dec 11, 2018, 8:06:59 AM12/11/18
to openresty
已经找到了。 

Automatic Error Logging

By default the underlying ngx_lua module does error logging when socket errors happen. If you are already doing proper error handling in your own Lua code, then you are recommended to disable this automatic error logging by turning off ngx_lua's lua_socket_log_errors directive, that is,

    lua_socket_log_errors off;

Back to TOC


在 2018年12月11日星期二 UTC+8下午8:59:34,老拐瘦&拐爷写道:

朱大仙儿

unread,
Dec 11, 2018, 10:29:11 PM12/11/18
to openresty
顺便问一下,你这个lua的服务跑在哪,可以一直监听订阅
nginx lua 如何启动一个服务,一直运行





------------------
 
 
 
------------------ Original ------------------
From:  "老拐瘦&拐爷"<geyu...@gmail.com>;
Date:  Tue, Dec 11, 2018 09:06 PM
To:  "openresty"<open...@googlegroups.com>;
Subject:  [openresty] Re: 如何关掉 redis 里的 timeout
 
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

葛 云飞

unread,
Dec 11, 2018, 10:30:35 PM12/11/18
to open...@googlegroups.com

Hi,

是跑在 init_by_worker 这个生命周期里的

 

但是目前来看,还是有 timeout 超时

 

发件人: "open...@googlegroups.com" <open...@googlegroups.com> 代表 朱大仙儿 <zhuho...@tvmining.com>
答复: "open...@googlegroups.com" <open...@googlegroups.com>
日期: 20181212 星期三 上午11:29
收件人: openresty <open...@googlegroups.com>
主题: Re:[openresty] Re: 如何关掉 redis 里的 timeout

tokers

unread,
Dec 12, 2018, 12:41:42 AM12/12/18
to openresty
Hello!

目前你可能只能通过手动判断超时情况然后主动再次去 subscribe 了。

另外你说在 init_by_worker,应该是启用了一个定时器的吧,
最好控制下这个定时器的存活时间,定时器一直不退出意味着相关内存得不到机会释放。

葛 云飞

unread,
Dec 12, 2018, 12:43:55 AM12/12/18
to open...@googlegroups.com

哦,不,我是用了一个协程来进行处理的

类似代码如下:

 

function M:subscribe(key,func)

    local co = coroutine.create(function()

        local red = get_con(self)

        local ok,err = red:subscribe(key,guid())

        if not ok then

            return err

        end

        local flag = true

        while flag do

            local res,err = red:read_reply()

            if err then

                ;

            else

                if res[1] == "message" then

                    local obj = cjson.decode(res[3])

                    flag = func(obj.msg)

                end

            end

       end

   end)

   coroutine.resume(co)

 

end

 

 

发件人: "open...@googlegroups.com" <open...@googlegroups.com> 代表 tokers <zcha...@gmail.com>
答复: "open...@googlegroups.com" <open...@googlegroups.com>
日期: 20181212 星期三 下午1:41

收件人: openresty <open...@googlegroups.com>
主题: Re: [openresty] Re: 如何关掉 redis 里的 timeout

 

Hello!

--
--

朱大仙儿

unread,
Dec 12, 2018, 1:10:41 AM12/12/18
to openresty
那你这个函数,谁来调用它呢?如果是在路由里,得client访问 /abc/def这样吧,至少有人访问一次,才能触发启动这个协程
你们是怎么让nginx触发启动的
function M:subscribe





 
 
------------------ Original ------------------
From:  "葛 云飞"<geyu...@gmail.com>;
Date:  Wed, Dec 12, 2018 01:43 PM
Subject:  Re: [openresty] Re: 如何关掉 redis 里的 timeout

葛 云飞

unread,
Dec 12, 2018, 1:32:42 AM12/12/18
to open...@googlegroups.com

这个是当 redis 里面有事件时就调用了啊。。。。

 

 

答复: "open...@googlegroups.com" <open...@googlegroups.com>
日期: 20181212 星期三 下午2:10

朱大仙儿

unread,
Dec 12, 2018, 1:39:56 AM12/12/18
to openresty

你理解错我说的了,redis有事件pub后,你的程序是可以sub到消息。关键是你这个sub的服务从哪里启动呢,你用了一个协程来跑,那谁来调用这个协程的函数呢



 
 
 
------------------ Original ------------------
From:  "葛 云飞"<geyu...@gmail.com>;
Date:  Wed, Dec 12, 2018 02:32 PM

葛 云飞

unread,
Dec 12, 2018, 2:27:59 AM12/12/18
to open...@googlegroups.com

我直接在init-by-worker 里启动这个协程的

不需要有外部服务触发

 

日期: 20181212 星期三 下午2:39

葛 云飞

unread,
Dec 12, 2018, 11:05:32 PM12/12/18
to open...@googlegroups.com

目前 这个 超时还是关不掉。。。

日期: 20181212 星期三 下午2:39

tianxia...@gmail.com

unread,
Dec 26, 2018, 2:08:54 AM12/26/18
to openresty
hi~
lua_resty_websocket 
这个就行
在 2018年12月12日星期三 UTC+8上午11:29:11,朱大仙儿写道:
Reply all
Reply to author
Forward
0 new messages