File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,8 @@ every command on a client.
198
198
Nagle algorithm on the underlying socket. Setting this option to ` false ` can result in additional throughput at the
199
199
cost of more latency. Most applications will want this set to ` true ` .
200
200
* ` socket_keepalive ` defaults to ` true ` . Whether the keep-alive functionality is enabled on the underlying socket.
201
+ * ` socket_connect_timeout ` defaults to ` null ` . By default a connection attempts use the operating system's timeout, but
202
+ setting ` socket_connect_timeout ` will time-out the connection attempt after this many milliseconds instead.
201
203
* ` no_ready_check ` : defaults to ` false ` . When a connection is established to the Redis server, the server might still
202
204
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
203
205
` node_redis ` has a "ready check" which sends the ` INFO ` command to the server. The response from the ` INFO ` command
Original file line number Diff line number Diff line change @@ -94,6 +94,12 @@ exports.RedisClient = RedisClient;
94
94
RedisClient . prototype . install_stream_listeners = function ( ) {
95
95
var self = this ;
96
96
97
+ if ( this . options . socket_connect_timeout > 0 ) {
98
+ this . stream . setTimeout ( this . options . socket_connect_timeout , function ( ) {
99
+ self . on_timeout ( ) ;
100
+ } ) ;
101
+ }
102
+
97
103
this . stream . on ( "connect" , function ( ) {
98
104
self . on_connect ( ) ;
99
105
} ) ;
@@ -247,6 +253,20 @@ RedisClient.prototype.do_auth = function () {
247
253
self . send_anyway = false ;
248
254
} ;
249
255
256
+ RedisClient . prototype . on_timeout = function ( ) {
257
+ if ( this . connected || this . closing ) {
258
+ // Only handle connection timeouts.
259
+ return ;
260
+ }
261
+
262
+ if ( exports . debug_mode ) {
263
+ console . log ( "Stream timeout " + this . address + " id " + this . connection_id ) ;
264
+ }
265
+
266
+ this . stream . end ( ) ;
267
+ this . connection_gone ( "timeout" ) ;
268
+ } ;
269
+
250
270
RedisClient . prototype . on_connect = function ( ) {
251
271
if ( exports . debug_mode ) {
252
272
console . log ( "Stream connected " + this . address + " id " + this . connection_id ) ;
You can’t perform that action at this time.
0 commit comments