首页 > 解决方案 > 如何为node_redis js配置TCP连接超时

问题描述

使用node_redis(js redis客户端)时有没有办法配置tcp连接超时?还是其他成熟的 JS redis 客户端?在我的 prod 环境中,当 redis 服务器被杀死时,连接重试时我的 TCP 连接超时时间很长(比如 130 秒)。所以即使 redis 服务器在 5 秒内开始响应,我的应用程序也会挂起 130s + 3s(在 retry_strategy 中配置)。我的重试策略:

            retry_strategy: (options) => {
            if (options.error) {
                RedisStore.log.debug(`${options.error.message}. Reconnecting in 3000`);
            }
            return 3000;
        }

我的应用程序日志输出显示问题:

2018-06-25T14:05:16.031Z debug Redis connection has been closed. ("end" event)
2018-06-25T14:05:19.037Z debug Reconnecting with Redis. ("reconnecting" event)
2018-06-25T14:07:28.102Z debug Redis connection to app-redis-master:6379 failed - connect ETIMEDOUT x.x.x.x:6379. Reconnecting in 3000ms. ("error" event - after 2min and 10s)

“结束”事件立即发出。问题是“错误”事件需要很长时间才能发出,并且 retry_strategy 在那段时间内没有再次触发。如何将超时配置为更短?

标签: socketstcpredistimeoutnode-redis

解决方案


推荐阅读