You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Rewrite createClient. Fixes #651
This commit is contained in:
49
index.js
49
index.js
@@ -1228,50 +1228,29 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.createClient = function(arg0, arg1, options) {
|
||||||
|
if (typeof arg0 === 'object' || arg0 === undefined) {
|
||||||
|
options = arg0 || options;
|
||||||
|
return createClient_tcp(default_port, default_host, options);
|
||||||
|
}
|
||||||
|
if (typeof arg0 === 'number' || typeof arg0 === 'string' && arg0.match(/^\d+$/)){
|
||||||
|
return createClient_tcp(arg0, arg1, options);
|
||||||
|
}
|
||||||
|
if (typeof arg0 === 'string') {
|
||||||
|
options = arg1 || {};
|
||||||
|
|
||||||
exports.createClient = function(arg0, arg1, arg2){
|
var parsed = URL.parse(arg0, true, true);
|
||||||
if( arguments.length === 0 ){
|
|
||||||
|
|
||||||
// createClient()
|
|
||||||
return createClient_tcp(default_port, default_host, {});
|
|
||||||
|
|
||||||
} else if( typeof arg0 === 'number' ||
|
|
||||||
typeof arg0 === 'string' && arg0.match(/^\d+$/) ){
|
|
||||||
|
|
||||||
// createClient( 3000, host, options)
|
|
||||||
// createClient('3000', host, options)
|
|
||||||
return createClient_tcp(arg0, arg1, arg2);
|
|
||||||
|
|
||||||
} else if( typeof arg0 === 'string' ){
|
|
||||||
var parsed = URL.parse(arg0, true, true),
|
|
||||||
options = (arg1 || {});
|
|
||||||
|
|
||||||
if (parsed.hostname) {
|
if (parsed.hostname) {
|
||||||
if (parsed.auth) {
|
if (parsed.auth) {
|
||||||
options.auth_pass = parsed.auth.split(':')[1];
|
options.auth_pass = parsed.auth.split(':')[1];
|
||||||
}
|
}
|
||||||
// createClient(3000, host, options)
|
|
||||||
return createClient_tcp((parsed.port || default_port), parsed.hostname, 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' ){
|
return createClient_unix(arg0, options);
|
||||||
|
|
||||||
// createClient(options)
|
|
||||||
return createClient_tcp(default_port, default_host, arg0 );
|
|
||||||
|
|
||||||
} else if( arg0 === null && arg1 === null ){
|
|
||||||
|
|
||||||
// for backward compatibility
|
|
||||||
// createClient(null,null,options)
|
|
||||||
return createClient_tcp(default_port, default_host, arg2);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new Error('unknown type of connection in createClient()');
|
|
||||||
}
|
}
|
||||||
}
|
throw new Error('unknown type of connection in createClient()');
|
||||||
|
};
|
||||||
|
|
||||||
var createClient_unix = function(path, options){
|
var createClient_unix = function(path, options){
|
||||||
var cnxOptions = {
|
var cnxOptions = {
|
||||||
|
Reference in New Issue
Block a user