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



当我的脚本空闲一段时间时,我收到了以下错误。我不明白这是什么原因。

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服务。

我们有一个完整的文档涵盖了这个主题:Redis超时的Azure缓存疑难解答

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

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]

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

最新更新