@@ -178,7 +178,7 @@ RedisClient.prototype.flush_and_error = function (message) {
178
178
} ;
179
179
180
180
RedisClient . prototype . on_error = function ( msg ) {
181
- var message = "Redis connection to " + this . host + ":" + this . port + " failed - " + msg ;
181
+ var message = "Redis connection to " + this . address + " failed - " + msg ;
182
182
183
183
if ( this . closing ) {
184
184
return ;
@@ -203,7 +203,7 @@ RedisClient.prototype.do_auth = function () {
203
203
var self = this ;
204
204
205
205
if ( exports . debug_mode ) {
206
- console . log ( "Sending auth to " + self . host + ":" + self . port + " id " + self . connection_id ) ;
206
+ console . log ( "Sending auth to " + self . address + " id " + self . connection_id ) ;
207
207
}
208
208
self . send_anyway = true ;
209
209
self . send_command ( "auth" , [ this . auth_pass ] , function ( err , res ) {
@@ -227,7 +227,7 @@ RedisClient.prototype.do_auth = function () {
227
227
return self . emit ( "error" , new Error ( "Auth failed: " + res . toString ( ) ) ) ;
228
228
}
229
229
if ( exports . debug_mode ) {
230
- console . log ( "Auth succeeded " + self . host + ":" + self . port + " id " + self . connection_id ) ;
230
+ console . log ( "Auth succeeded " + self . address + " id " + self . connection_id ) ;
231
231
}
232
232
if ( self . auth_callback ) {
233
233
self . auth_callback ( err , res ) ;
@@ -249,7 +249,7 @@ RedisClient.prototype.do_auth = function () {
249
249
250
250
RedisClient . prototype . on_connect = function ( ) {
251
251
if ( exports . debug_mode ) {
252
- console . log ( "Stream connected " + this . host + ":" + this . port + " id " + this . connection_id ) ;
252
+ console . log ( "Stream connected " + this . address + " id " + this . connection_id ) ;
253
253
}
254
254
255
255
this . connected = true ;
@@ -532,15 +532,15 @@ RedisClient.prototype.connection_gone = function (why) {
532
532
return ;
533
533
}
534
534
535
- self . stream = net . createConnection ( self . port , self . host ) ;
535
+ self . stream = net . createConnection ( self . connectionOption ) ;
536
536
self . install_stream_listeners ( ) ;
537
537
self . retry_timer = null ;
538
538
} , this . retry_delay ) ;
539
539
} ;
540
540
541
541
RedisClient . prototype . on_data = function ( data ) {
542
542
if ( exports . debug_mode ) {
543
- console . log ( "net read " + this . host + ":" + this . port + " id " + this . connection_id + ": " + data . toString ( ) ) ;
543
+ console . log ( "net read " + this . address + " id " + this . connection_id + ": " + data . toString ( ) ) ;
544
544
}
545
545
546
546
try {
@@ -852,7 +852,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
852
852
command_str += "$" + Buffer . byteLength ( arg ) + "\r\n" + arg + "\r\n" ;
853
853
}
854
854
if ( exports . debug_mode ) {
855
- console . log ( "send " + this . host + ":" + this . port + " id " + this . connection_id + ": " + command_str ) ;
855
+ console . log ( "send " + this . address + " id " + this . connection_id + ": " + command_str ) ;
856
856
}
857
857
buffered_writes += ! stream . write ( command_str ) ;
858
858
} else {
@@ -1213,28 +1213,64 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
1213
1213
} ;
1214
1214
1215
1215
1216
- exports . createClient = function ( port_arg , host_arg , options ) {
1216
+ exports . createClient = function ( arg0 , arg1 , arg2 ) {
1217
+ if ( arguments . length === 0 ) {
1217
1218
1218
- var cnxFamily ;
1219
-
1220
- if ( options && options . family ) {
1221
- cnxFamily = ( options . family == 'IPv6' ? 6 : 4 ) ;
1222
- }
1223
-
1219
+ // createClient()
1220
+ return createClient_tcp ( default_port , default_host , { } ) ;
1221
+
1222
+ } else if ( typeof arg0 === 'number' ||
1223
+ typeof arg0 === 'string' && arg0 . match ( / ^ \d + $ / ) ) {
1224
+
1225
+ // createClient( 3000, host, options)
1226
+ // createClient('3000', host, options)
1227
+ return createClient_tcp ( arg0 , arg1 , arg2 ) ;
1228
+
1229
+ } else if ( typeof arg0 === 'string' ) {
1230
+
1231
+ // createClient( '/tmp/redis.sock', options)
1232
+ return createClient_unix ( arg0 , arg1 ) ;
1233
+
1234
+ } else if ( arg0 !== null && typeof arg0 === 'object' ) {
1235
+
1236
+ // createClient(options)
1237
+ return createClient_tcp ( default_port , default_host , arg0 ) ;
1238
+
1239
+ } else if ( arg0 === null && arg1 === null ) {
1240
+
1241
+ // for backward compatibility
1242
+ // createClient(null,null,options)
1243
+ return createClient_tcp ( default_port , default_host , arg2 ) ;
1244
+
1245
+ } else {
1246
+ throw new Error ( 'unknown type of connection in createClient()' ) ;
1247
+ }
1248
+ }
1249
+
1250
+ var createClient_unix = function ( path , options ) {
1224
1251
var cnxOptions = {
1225
- 'port' : port_arg || default_port ,
1226
- 'host' : host_arg || default_host ,
1227
- 'family' : cnxFamily || '4'
1252
+ path : path
1228
1253
} ;
1254
+ var net_client = net . createConnection ( cnxOptions ) ;
1255
+ var redis_client = new RedisClient ( net_client , options || { } ) ;
1229
1256
1230
- var redis_client , net_client ;
1257
+ redis_client . connectionOption = cnxOptions ;
1258
+ redis_client . address = path ;
1231
1259
1232
- net_client = net . createConnection ( cnxOptions ) ;
1260
+ return redis_client ;
1261
+ }
1233
1262
1234
- redis_client = new RedisClient ( net_client , options ) ;
1263
+ var createClient_tcp = function ( port_arg , host_arg , options ) {
1264
+ var cnxOptions = {
1265
+ 'port' : port_arg || default_port ,
1266
+ 'host' : host_arg || default_host ,
1267
+ 'family' : ( options && options . family === 'IPv6' ) ? 'IPv6' : 'IPv4'
1268
+ } ;
1269
+ var net_client = net . createConnection ( cnxOptions ) ;
1270
+ var redis_client = new RedisClient ( net_client , options || { } ) ;
1235
1271
1236
- redis_client . port = cnxOptions . port ;
1237
- redis_client . host = cnxOptions . host ;
1272
+ redis_client . connectionOption = cnxOptions ;
1273
+ redis_client . address = cnxOptions . host + ':' + cnxOptions . port ;
1238
1274
1239
1275
return redis_client ;
1240
1276
} ;
0 commit comments