@@ -69,8 +69,17 @@ function RedisClient(stream, options) {
69
69
70
70
this . old_state = null ;
71
71
72
- var self = this ;
72
+ if ( this . stream ) {
73
+ this . initialize_stream_listeners ( ) ;
74
+ }
73
75
76
+ events . EventEmitter . call ( this ) ;
77
+ }
78
+ util . inherits ( RedisClient , events . EventEmitter ) ;
79
+ exports . RedisClient = RedisClient ;
80
+
81
+ RedisClient . prototype . initialize_stream_listeners = function ( ) {
82
+ var self = this ;
74
83
this . stream . on ( "connect" , function ( ) {
75
84
self . on_connect ( ) ;
76
85
} ) ;
@@ -95,11 +104,7 @@ function RedisClient(stream, options) {
95
104
self . should_buffer = false ;
96
105
self . emit ( "drain" ) ;
97
106
} ) ;
98
-
99
- events . EventEmitter . call ( this ) ;
100
- }
101
- util . inherits ( RedisClient , events . EventEmitter ) ;
102
- exports . RedisClient = RedisClient ;
107
+ } ;
103
108
104
109
RedisClient . prototype . initialize_retry_vars = function ( ) {
105
110
this . retry_timer = null ;
@@ -468,6 +473,12 @@ RedisClient.prototype.connection_gone = function (why) {
468
473
} ;
469
474
470
475
RedisClient . prototype . forceReconnectionAttempt = function ( ) {
476
+ if ( ! this . stream ) {
477
+ this . stream = net . createConnection ( this . port , this . host ) ;
478
+ this . initialize_stream_listeners ( ) ;
479
+ return ;
480
+ }
481
+
471
482
clearTimeout ( this . retry_timer ) ;
472
483
this . initialize_retry_vars ( ) ;
473
484
this . connection_gone ( ) ;
@@ -1098,11 +1109,20 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
1098
1109
1099
1110
1100
1111
exports . createClient = function ( port_arg , host_arg , options ) {
1101
- var port = port_arg || default_port ,
1102
- host = host_arg || default_host ,
1103
- redis_client , net_client ;
1112
+ var redis_client ;
1113
+ var net_client ;
1114
+
1115
+ var port = port_arg ,
1116
+ host = host_arg ;
1117
+
1118
+ options = options || { } ;
1104
1119
1105
- net_client = net . createConnection ( port , host ) ;
1120
+ if ( options . allowNoSocket !== true || ( port_arg !== null && host_arg !== null ) ) {
1121
+ host = host || default_host ;
1122
+ port = port || default_port ;
1123
+
1124
+ net_client = net . createConnection ( port , host ) ;
1125
+ }
1106
1126
1107
1127
redis_client = new RedisClient ( net_client , options ) ;
1108
1128
0 commit comments