diff --git a/README.md b/README.md index eb05cc864f6..b2089159919 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,7 @@ __Note:__ Using `'rediss://...` for the protocol in a `redis_url` will enable a | return_buffers | false | If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings. | | detect_buffers | false | If set to `true`, then replies will be sent to callbacks as Buffers. This option lets you switch between Buffers and Strings on a per-command basis, whereas `return_buffers` applies to every command on a client. __Note__: This doesn't work properly with the pubsub mode. A subscriber has to either always return Strings or Buffers. | | socket_keepalive | true | If set to `true`, the keep-alive functionality is enabled on the underlying socket. | +| socket_initialdelay | 0 | Initial Delay in milliseconds, and this will also behave the interval keep alive message sending to Redis. | | no_ready_check | false | When a connection is established to the Redis server, the server might still be loading the database from disk. While loading, the server will not respond to any commands. To work around this, `node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event. Setting `no_ready_check` to `true` will inhibit this check. | | enable_offline_queue | true | By default, if there is no active connection to the Redis server, commands are added to a queue and are executed once the connection has been established. Setting `enable_offline_queue` to `false` will disable this feature and the callback will be executed immediately with an error, or an error will be emitted if no callback is specified. | | 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. | diff --git a/index.js b/index.js index 271d53db437..ce667a9dd49 100644 --- a/index.js +++ b/index.js @@ -101,6 +101,10 @@ function RedisClient (options, stream) { if (options.socket_keepalive === undefined) { options.socket_keepalive = true; } + if (options.socket_initialdelay === undefined) { + options.socket_initialdelay = 0; + // set default to 0, which is aligned to https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay + } for (var command in options.rename_commands) { options.rename_commands[command.toLowerCase()] = options.rename_commands[command]; } @@ -416,7 +420,7 @@ RedisClient.prototype.on_connect = function () { this.connected = true; this.ready = false; this.emitted_end = false; - this.stream.setKeepAlive(this.options.socket_keepalive); + this.stream.setKeepAlive(this.options.socket_keepalive, this.options.socket_initialdelay); this.stream.setTimeout(0); this.emit('connect');