[英]Why does ioredis client timeout when keep-alive is enabled?
I have been getting the following error, when my script stays idle for sometime.当我的脚本闲置一段时间时,我收到以下错误。 I cannot understand the reason for this.
我无法理解这样做的原因。
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)
I initialize my redis client as :我将我的 redis 客户端初始化为:
let redis = require("ioredis");
redis = Promise.promisifyAll(redis);
const redis = new redis({
host: "my hostname",
port: 6379,
password: "some password"
});
and I am using ioredis client .我正在使用ioredis 客户端。
Does anyone know the reason for this?有谁知道这是什么原因? The keep-alive is already enabled by default as suggested here https://github.com/luin/ioredis/blob/master/API.md
按照此处的建议,默认情况下已启用保持活动状态https://github.com/luin/ioredis/blob/master/API.md
I want the client to never timeout and reconnect if the timeout occurs.我希望客户端永远不会超时并在超时发生时重新连接。 I am using Redis service by azure.
我正在使用 azure 的 Redis 服务。
We have an entire document that covers this topic: Troubleshoot Azure Cache for Redis timeouts我们有一个涵盖此主题的完整文档: 对 Azure Redis 缓存超时进行故障排除
If using the StackExchange.Redis Client the best practice of using the following pattern is suggested:如果使用 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;
}
}
In the case of ioredis, you can set a client property: [options.lazyConnect]
在ioredis的情况下,你可以设置一个客户端属性:
[options.lazyConnect]
You will also want to look at any retry methods available with your client.您还需要查看客户端可用的任何重试方法。 I hope this helps.
我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.