Redis connection gone from close event

微笑、不失礼 提交于 2019-12-04 07:45:18

We had a bunch of connection trouble with Redis as well. It seems like it would close the connection without it telling the client. We noticed that it was possibly a timeout problem on the server. This is the solution that we use and we haven't had a problem since July.

var RETRY_EVERY = 1000 * 60 * 3;
var startTimer = function(){
    console.log('Begin the hot tub!')
    setInterval(function(){
        try{
            client.set('hot',new Date());
            console.log(client.get('hot'))
        }
        catch(e){
            console.log(e);
        }

    },RETRY_EVERY)
}();

Considering it's only one call every 3 minutes, it shouldn't be a problem for performance ;)

With regards to oconnecp's answer, can't you just do:

setInterval(client.ping(), 1000 * 60 * 30);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!