Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added URL support to createClient #658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -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' ){

Expand Down
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,25 @@ tests.auth2 = function () {
});
};

// auth password specified by URL string.
tests.auth3 = function () {
var name = "AUTH3", client4, ready_count = 0;

client4 = redis.createClient('redis://redistogo:664b1b6aaf134e1ec281945a8de702a9@filefish.redistogo.com:9006/');

// test auth, then kill the connection so it'll auto-reconnect and auto-re-auth
client4.on("ready", function () {
ready_count++;
if (ready_count === 1) {
client4.stream.destroy();
} else {
client4.quit(function (err, res) {
next(name);
});
}
});
};

tests.reconnectRetryMaxDelay = function() {
var time = new Date().getTime(),
name = 'reconnectRetryMaxDelay',
Expand Down