Open
Description
I've recently upgraded to node redis 4.1.0 and I'm having issues with reconnectStrategy and connection handling in general.
Logs from reconnectstrategy are never printed.
When I start with redis server down. I still get the ready event triggered. A bit later I get an error event and it immediately "connects" (triggering ready again); And this just continues; The 5 second reconnect timer is not used.
When redis is online when I start the application and I later turn it off: it seems to go even faster. It does not wait long between the ready event and an error.
I'm initializing redis like so:
const options: RedisClientOptions<RedisModules, RedisFunctions, S> = {
username: this.username,
password: this.password,
socket: {
host: this.host,
port: this.port,
reconnectStrategy: (attempts) => {
console.log(`Redis reconnecting attempt ${attempts}`);
this.connected = false;
if (attempts == 1) {
console.log(`${this.constructor.name} failed to connect to ${this.host}:${this.port}. Reconnecting...`);
}
return 5000;
},
},
scripts: scripts,
};
const redisClient = createClient(options);
redisClient.on('ready', () => {
console.log(`${this.constructor.name} connected to ${this.host}:${this.port}`);
});
redisClient.on('error', (err) => {
console.log('error');
return;
});
redisClient.on('reconnecting', () => {
return;
});
redisClient.on('end', () => {
return;
});
redisClient.on('connect', () => {
return;
});
redisClient.connect();
Environment:
- Node.js Version: v14.16.0
- Node Redis Version: 4.1.0
- Platform: Mac OS 12.3.1