node-redis retry_strategy 有默认值吗?
node-redis Does retry_strategy have a default value?
Redis 连接有效,即使 redis-server 已停止并且
在没有 retry_strategy 选项的情况下重新启动。
const conn = redis.createClient({
host: 'redisUrl',
port: 'redisPort',
...
socket_keepalive : true
});
redisClient.on('connect', () => {
console.log(`connect`);
}).on('error', () => {
console.log(`error`);
});
为什么?
是的,node-redis
确实有他们 README 中概述的默认策略。 但是,所有这些现在都已弃用,取而代之的是 retry_strategy
函数。
具体来说,查找 retry_max_delay
、connect_timeout
和 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.
Redis 连接有效,即使 redis-server 已停止并且 在没有 retry_strategy 选项的情况下重新启动。
const conn = redis.createClient({
host: 'redisUrl',
port: 'redisPort',
...
socket_keepalive : true
});
redisClient.on('connect', () => {
console.log(`connect`);
}).on('error', () => {
console.log(`error`);
});
为什么?
是的,node-redis
确实有他们 README 中概述的默认策略。 但是,所有这些现在都已弃用,取而代之的是 retry_strategy
函数。
具体来说,查找 retry_max_delay
、connect_timeout
和 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.