File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,8 @@ every command on a client.
181
181
Nagle algorithm on the underlying socket. Setting this option to ` false ` can result in additional throughput at the
182
182
cost of more latency. Most applications will want this set to ` true ` .
183
183
* ` socket_keepalive ` defaults to ` true ` . Whether the keep-alive functionality is enabled on the underlying socket.
184
+ * ` socket_connect_timeout ` defaults to ` null ` . By default a connection attempts use the operating system's timeout, but
185
+ setting ` socket_connect_timeout ` will time-out the connection attempt after this many milliseconds instead.
184
186
* ` no_ready_check ` : defaults to ` false ` . When a connection is established to the Redis server, the server might still
185
187
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
186
188
` 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 @@ -81,6 +81,12 @@ exports.RedisClient = RedisClient;
81
81
RedisClient . prototype . install_stream_listeners = function ( ) {
82
82
var self = this ;
83
83
84
+ if ( this . options . socket_connect_timeout > 0 ) {
85
+ this . stream . setTimeout ( this . options . socket_connect_timeout , function ( ) {
86
+ self . on_timeout ( ) ;
87
+ } ) ;
88
+ }
89
+
84
90
this . stream . on ( "connect" , function ( ) {
85
91
self . on_connect ( ) ;
86
92
} ) ;
@@ -218,6 +224,20 @@ RedisClient.prototype.do_auth = function () {
218
224
self . send_anyway = false ;
219
225
} ;
220
226
227
+ RedisClient . prototype . on_timeout = function ( ) {
228
+ if ( this . connected || this . closing ) {
229
+ // Only handle connection timeouts.
230
+ return ;
231
+ }
232
+
233
+ if ( exports . debug_mode ) {
234
+ console . log ( "Stream timeout " + this . address + " id " + this . connection_id ) ;
235
+ }
236
+
237
+ this . stream . end ( ) ;
238
+ this . connection_gone ( "timeout" ) ;
239
+ } ;
240
+
221
241
RedisClient . prototype . on_connect = function ( ) {
222
242
debug ( "Stream connected " + this . address + " id " + this . connection_id ) ;
223
243
You can’t perform that action at this time.
0 commit comments