繁体   English   中英

为什么启用保持活动时ioredis客户端超时?

[英]Why does ioredis client timeout when keep-alive is enabled?

当我的脚本闲置一段时间时,我收到以下错误。 我无法理解这样做的原因。

    error: [ioredis] Unhandled error event: 
error: Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27) 
error: [ioredis] Unhandled error event
error: Error: read ETIMEDOUT
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27) 

我将我的 redis 客户端初始化为:

let redis = require("ioredis");
redis = Promise.promisifyAll(redis);

const redis = new redis({
   host: "my hostname",
   port: 6379,
   password: "some password"
});

我正在使用ioredis 客户端

有谁知道这是什么原因? 按照此处的建议,默认情况下已启用保持活动状态https://github.com/luin/ioredis/blob/master/API.md

我希望客户端永远不会超时并在超时发生时重新连接。 我正在使用 azure 的 Redis 服务。

我们有一个涵盖此主题的完整文档: 对 Azure Redis 缓存超时进行故障排除

如果使用 StackExchange.Redis 客户端,建议使用以下模式的最佳实践:

private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("cachename.redis.cache.windows.net,abortConnect=false,ssl=true,password=...");
});
public static ConnectionMultiplexer Connection
   {
get
{
return lazyConnection.Value;
}
}

在ioredis的情况下,你可以设置一个客户端属性: [options.lazyConnect]

您还需要查看客户端可用的任何重试方法。 我希望这有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM