Skip to content

Commit d313aa5

Browse files
committed
param socket_keepalive to set keep-alive on socket
1 parent 4672479 commit d313aa5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ every command on a client.
192192
* `socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
193193
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
194194
cost of more latency. Most applications will want this set to `true`.
195+
* `socket_keepalive` defaults to `false`. Whether the keep-alive functionality is enabled on the underlying socket.
195196
* `no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
196197
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
197198
`node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function RedisClient(stream, options) {
4343
if (this.options.socket_nodelay === undefined) {
4444
this.options.socket_nodelay = true;
4545
}
46+
if (this.options.socket_keepalive === undefined) {
47+
this.options.socket_keepalive = false;
48+
}
4649
this.should_buffer = false;
4750
this.command_queue_high_water = this.options.command_queue_high_water || 1000;
4851
this.command_queue_low_water = this.options.command_queue_low_water || 0;
@@ -249,6 +252,7 @@ RedisClient.prototype.on_connect = function () {
249252
if (this.options.socket_nodelay) {
250253
this.stream.setNoDelay();
251254
}
255+
this.stream.setKeepAlive(this.options.socket_keepalive);
252256
this.stream.setTimeout(0);
253257

254258
this.init_parser();

0 commit comments

Comments
 (0)