sockets - 如何为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 在那段时间内没有再次触发。如何将超时配置为更短?
解决方案
推荐阅读
- excel - 在宏外部声明的变量的“编译错误:未定义变量”
- dynamics-crm - 如何防止重复的 Dynamics CRM 插件步骤
- odoo - 如何在字段 odoo 11 中将默认值设置为年份?
- python - 我只是不能将同名的行添加到另一个数据集?
- javascript - 收音机 onClick 更改
- flutter - Flutter Web 中带有粘性页眉和页脚的动态表格
- r - 使用具有多个匹配的另一个数据框替换字符值
- python - Pandas pivot_table 包括空身份
- python - 在 Microsoft Academic API 查询中转义 '
- react-native - 与子交互时调用父 onPress 方法