简体   繁体   中英

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 :

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 .

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

I want the client to never timeout and reconnect if the timeout occurs. I am using Redis service by azure.

We have an entire document that covers this topic: Troubleshoot Azure Cache for Redis timeouts

If using the StackExchange.Redis Client the best practice of using the following pattern is suggested:

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]

You will also want to look at any retry methods available with your client. I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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