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

Rewrite createClient. Fixes #651 #786

Merged
merged 1 commit into from
Jul 22, 2015
Merged
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
49 changes: 14 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
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 || {});

var parsed = URL.parse(arg0, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like URL.parse does not return a parsed.port when the string is only a string number like "6379", so this introduces breaking changes. Am I wrong?

erin@elisheva:~/node_redis$ node  -e "var URL = require('url'); console.log(URL.parse('8000'));"
{ protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '8000',
  path: '8000',
  href: '8000' }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test every possibility and would like to add some before this is merged but I'm quite certain the behavior is just the same as it was before. There should not be any BC.

This code is the same as it was before in line 1245.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, you're right. Looks like this bug predates your PR. Also, all of the new mocha tests (which test all applicable combinations of ipv4, ipv6, hiredis, javascript, and unix sockets) pass against this.

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' ){

// 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()');
return createClient_unix(arg0, options);
}
}
throw new Error('unknown type of connection in createClient()');
};

var createClient_unix = function(path, options){
var cnxOptions = {
Expand Down