I'm trying to handle redis retry connection if there's any network issue. It looks like it's working but I'm not sure because sometimes I get ECONNRESET.
redisOptions: {
sentinels: [
{ host: process.env.redis_server_1, port: process.env.redis_port_1 },
{ host: process.env.redis_server_2, port: process.env.redis_port_2 },
{ host: process.env.redis_server_3, port: process.env.redis_port_3 },
],
name: 'mymaster'
},
redisOptions object is defined in configuration file.
function updateConfigurations(){
console.log(configuration.redisOptions);
configuration.redisOptions.sentinelRetryStrategy = (times) => {
console.log('Trying to connect to Redis ', times);
return Math.min(times * 100, 10000);
}
// configuration.redisOptions.retryStrategy = (times) => Math.min(times * 50, 2000);
}
I'm testing this by disconnecting from VPN. The moment I disconnected from VPN, below error message is getting printed on console.
[ioredis] Unhandled error event: Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
And then below logging for retry connecting
[ioredis] Unhandled error event: Error: All sentinels are unreachable. Retrying from scratch after 400ms. Last error: Connection is closed.
Is this a correct way to handle retry connecting? How should I handle ECONNRESET?