Skip to content

Commit 208b787

Browse files
author
Ruben Bridgewater
committed
Rewrite createClient. Fixes #651
1 parent e4da320 commit 208b787

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

index.js

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,50 +1228,29 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
12281228
});
12291229
};
12301230

1231+
exports.createClient = function(arg0, arg1, options) {
1232+
if (typeof arg0 === 'object' || arg0 === undefined) {
1233+
options = arg0 || options;
1234+
return createClient_tcp(default_port, default_host, options);
1235+
}
1236+
if (typeof arg0 === 'number' || typeof arg0 === 'string' && arg0.match(/^\d+$/)){
1237+
return createClient_tcp(arg0, arg1, options);
1238+
}
1239+
if (typeof arg0 === 'string') {
1240+
options = arg1 || {};
12311241

1232-
exports.createClient = function(arg0, arg1, arg2){
1233-
if( arguments.length === 0 ){
1234-
1235-
// createClient()
1236-
return createClient_tcp(default_port, default_host, {});
1237-
1238-
} else if( typeof arg0 === 'number' ||
1239-
typeof arg0 === 'string' && arg0.match(/^\d+$/) ){
1240-
1241-
// createClient( 3000, host, options)
1242-
// createClient('3000', host, options)
1243-
return createClient_tcp(arg0, arg1, arg2);
1244-
1245-
} else if( typeof arg0 === 'string' ){
1246-
var parsed = URL.parse(arg0, true, true),
1247-
options = (arg1 || {});
1248-
1242+
var parsed = URL.parse(arg0, true, true);
12491243
if (parsed.hostname) {
12501244
if (parsed.auth) {
12511245
options.auth_pass = parsed.auth.split(':')[1];
12521246
}
1253-
// createClient(3000, host, options)
12541247
return createClient_tcp((parsed.port || default_port), parsed.hostname, options);
1255-
} else {
1256-
// createClient( '/tmp/redis.sock', options)
1257-
return createClient_unix(arg0,options);
12581248
}
12591249

1260-
} else if( arg0 !== null && typeof arg0 === 'object' ){
1261-
1262-
// createClient(options)
1263-
return createClient_tcp(default_port, default_host, arg0 );
1264-
1265-
} else if( arg0 === null && arg1 === null ){
1266-
1267-
// for backward compatibility
1268-
// createClient(null,null,options)
1269-
return createClient_tcp(default_port, default_host, arg2);
1270-
1271-
} else {
1272-
throw new Error('unknown type of connection in createClient()');
1250+
return createClient_unix(arg0, options);
12731251
}
1274-
}
1252+
throw new Error('unknown type of connection in createClient()');
1253+
};
12751254

12761255
var createClient_unix = function(path, options){
12771256
var cnxOptions = {

0 commit comments

Comments
 (0)