Skip to content

Commit 304abe4

Browse files
author
Ruben Bridgewater
committed
Fix individual createClient functions passing undefined options to a new instance. Closes #893
1 parent ce4a67b commit 304abe4

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
## v.2.2.5 - 18 Oct, 2015
5+
6+
Bugfixes
7+
8+
- Fixed undefined options passed to a new instance not accepted (possible with individual .createClient functions) ([@BridgeAR](https://github.com/BridgeAR))
9+
410
## v.2.2.4 - 17 Oct, 2015
511

612
Bugfixes

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ parsers.push(require('./lib/parsers/javascript'));
3636

3737
function RedisClient(stream, options) {
3838
// Copy the options so they are not mutated
39-
options = JSON.parse(JSON.stringify(options));
39+
options = JSON.parse(JSON.stringify(options || {}));
4040
var self = this;
4141

4242
if (!stream.cork) {

test/connection.spec.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var assert = require("assert");
44
var config = require("./lib/config");
55
var helper = require('./helper');
66
var redis = config.redis;
7+
var net = require('net');
78

89
describe("connection tests", function () {
910
helper.allTests(function(parser, ip, args) {
@@ -186,27 +187,16 @@ describe("connection tests", function () {
186187
});
187188
});
188189

189-
it("buffer commands and flush them after ", function (done) {
190-
client = redis.createClient(9999, null, {
191-
parser: parser
192-
});
193-
194-
client.on('error', function(e) {
195-
// ignore, b/c expecting a "can't connect" error
196-
});
197-
198-
return setTimeout(function() {
199-
client.set('foo', 'bar', function(err, result) {
200-
// This should never be called
201-
return done(err);
202-
});
203-
204-
return setTimeout(function() {
205-
assert.strictEqual(client.offline_queue.length, 1);
206-
return done();
207-
}, 25);
208-
}, 50);
209-
});
190+
it("works with missing options object for new redis instances", function () {
191+
// This is needed for libraries that have their own createClient function like fakeredis
192+
var cnxOptions = {
193+
port : 6379,
194+
host : '127.0.0.1',
195+
family : ip === 'IPv6' ? 6 : 4
196+
};
197+
var net_client = net.createConnection(cnxOptions);
198+
client = new redis.RedisClient(net_client);
199+
});
210200

211201
it("throws on strange connection info", function () {
212202
try {

0 commit comments

Comments
 (0)