1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

added URL support to createClient

This commit is contained in:
Hiroshi Kuwabara
2014-09-12 12:37:32 +09:00
parent de6692774f
commit a67d3acdd6
2 changed files with 32 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
/*global Buffer require exports console setTimeout */
var net = require("net"),
URL = require("url"),
util = require("./lib/util"),
Queue = require("./lib/queue"),
to_array = require("./lib/to_array"),
@@ -1227,9 +1228,19 @@ exports.createClient = function(arg0, arg1, arg2){
return createClient_tcp(arg0, arg1, arg2);
} else if( typeof arg0 === 'string' ){
var parsed = URL.parse(arg0, true, true),
options = (arg1 || {});
// createClient( '/tmp/redis.sock', options)
return createClient_unix(arg0,arg1);
if (parsed.hostname) {
if (parsed.auth) {
options.auth_pass = parsed.auth.split(':')[1];
}
// createClient(3000, host, options)
return createClient_tcp((parsed.port || default_port), parsed.hostname, options);
} else {
// createClient( '/tmp/redis.sock', options)
return createClient_unix(arg0,options);
}
} else if( arg0 !== null && typeof arg0 === 'object' ){