Skip to content

Commit 95b8f1a

Browse files
authored
Merge pull request #1396 from betimer/master
Add delay option for socket.setKeepAlive
2 parents bd66d62 + 3a615e8 commit 95b8f1a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ __Note:__ Using `'rediss://...` for the protocol in a `redis_url` will enable a
247247
| return_buffers | false | If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings. |
248248
| 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. |
249249
| socket_keepalive | true | If set to `true`, the keep-alive functionality is enabled on the underlying socket. |
250+
| socket_initialdelay | 0 | Initial Delay in milliseconds, and this will also behave the interval keep alive message sending to Redis. |
250251
| 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. |
251252
| 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. |
252253
| 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. |

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ function RedisClient (options, stream) {
101101
if (options.socket_keepalive === undefined) {
102102
options.socket_keepalive = true;
103103
}
104+
if (options.socket_initialdelay === undefined) {
105+
options.socket_initialdelay = 0;
106+
// set default to 0, which is aligned to https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay
107+
}
104108
for (var command in options.rename_commands) {
105109
options.rename_commands[command.toLowerCase()] = options.rename_commands[command];
106110
}
@@ -416,7 +420,7 @@ RedisClient.prototype.on_connect = function () {
416420
this.connected = true;
417421
this.ready = false;
418422
this.emitted_end = false;
419-
this.stream.setKeepAlive(this.options.socket_keepalive);
423+
this.stream.setKeepAlive(this.options.socket_keepalive, this.options.socket_initialdelay);
420424
this.stream.setTimeout(0);
421425

422426
this.emit('connect');

0 commit comments

Comments
 (0)