File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -181,6 +181,8 @@ every command on a client.
181181Nagle algorithm on the underlying socket. Setting this option to ` false ` can result in additional throughput at the
182182cost of more latency. Most applications will want this set to ` true ` .
183183* ` 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.
184186* ` no_ready_check ` : defaults to ` false ` . When a connection is established to the Redis server, the server might still
185187be loading the database from disk. While loading, the server not respond to any commands. To work around this,
186188` 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;
8181RedisClient . prototype . install_stream_listeners = function ( ) {
8282 var self = this ;
8383
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+
8490 this . stream . on ( "connect" , function ( ) {
8591 self . on_connect ( ) ;
8692 } ) ;
@@ -218,6 +224,18 @@ RedisClient.prototype.do_auth = function () {
218224 self . send_anyway = false ;
219225} ;
220226
227+ RedisClient . prototype . on_timeout = function ( ) {
228+ if ( this . connected || this . closing ) {
229+ // Only handle connection timeouts.
230+ return ;
231+ }
232+
233+ debug ( "Stream timeout " + this . address + " id " + this . connection_id ) ;
234+
235+ this . stream . end ( ) ;
236+ this . connection_gone ( "timeout" ) ;
237+ } ;
238+
221239RedisClient . prototype . on_connect = function ( ) {
222240 debug ( "Stream connected " + this . address + " id " + this . connection_id ) ;
223241
You can’t perform that action at this time.
0 commit comments