Browse Source

Add host and port to options object

greenkeeper-update-all
Ruben Bridgewater 9 years ago
parent
commit
977d4dba2b
  1. 3
      changelog.md
  2. 6
      index.js
  3. 28
      test/connection.spec.js

3
changelog.md

@ -5,7 +5,8 @@ Changelog
Features:
- Add optional flush parameter to `.end`. If set to true, commands fired after using .end are going to be rejected instead of being ignored. (@crispy1989)
- Addded optional flush parameter to `.end`. If set to true, commands fired after using .end are going to be rejected instead of being ignored. (@crispy1989)
- Addded: host and port can now be provided in a single options object. E.g. redis.createClient({ host: 'localhost', port: 1337, max_attempts: 5 }); (@BridgeAR)
Bugfixes:

6
index.js

@ -1107,8 +1107,10 @@ var createClient_tcp = function (port_arg, host_arg, options) {
exports.createClient = function(port_arg, host_arg, options) {
if (typeof port_arg === 'object' || port_arg === undefined) {
options = port_arg || options;
return createClient_tcp(default_port, default_host, options);
options = port_arg || options || {};
var host = options.host || default_host;
var port = +options.port || default_port;
return createClient_tcp(port, host, options);
}
if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) {
return createClient_tcp(port_arg, host_arg, options);

28
test/connection.spec.js

@ -79,6 +79,34 @@ describe("on lost connection", function () {
});
});
it("can not connect with wrong host / port in the options object", function (done) {
var client = redis.createClient({
host: 'somewhere',
port: 6379,
max_attempts: 1
});
var end = helper.callFuncAfter(done, 2);
client.on('error', function (err) {
assert(/CONNECTION_BROKEN|ENOTFOUND/.test(err.code));
end();
});
});
it("connect with host and port provided in the options object", function (done) {
var client = redis.createClient({
host: 'localhost',
port: '6379',
parser: parser,
connect_timeout: 1000
});
client.once('ready', function() {
done();
});
});
});
});
});

Loading…
Cancel
Save