node.jsredisnode-redis

node-redis Does retry_strategy have a default value?


Redis connection was valid even when redis-server was stopped and restarted without the retry_strategy option.

const conn = redis.createClient({
    host: 'redisUrl',
    port: 'redisPort',
    ...
    socket_keepalive : true   
});

redisClient.on('connect', () => {
    console.log(`connect`);
}).on('error', () => {
    console.log(`error`);
});

Why?


Solution

  • Yes, node-redis did have a default strategy as outlined in their README. However, all of them are now deprecated in favor of retry_strategy function.

    Specifically, look for retry_max_delay, connect_timeout, and max_attempts.

    retry_max_delay null Deprecated Please use retry_strategy instead. By default, every time the client tries to connect and fails, the reconnection delay almost doubles. This delay normally grows infinitely, but setting retry_max_delay limits it to the maximum value provided in milliseconds.

    connect_timeout 3600000 Deprecated Please use retry_strategy instead. Setting connect_timeout limits the total time for the client to connect and reconnect. The value is provided in milliseconds and is counted from the moment a new client is created or from the time the connection is lost. The last retry is going to happen exactly at the timeout time. Default is to try connecting until the default system socket timeout has been exceeded and to try reconnecting until 1h has elapsed.

    max_attempts 0 Deprecated Please use retry_strategy instead. By default, a client will try reconnecting until connected. Setting max_attempts limits total amount of connection attempts. Setting this to 1 will prevent any reconnect attempt.