Skip to content

Commit

Permalink
Fix domain handling and tls camelCase settings
Browse files Browse the repository at this point in the history
Fixes #1106
Fixes #1103
Closes #1104
  • Loading branch information
Ruben Bridgewater committed Oct 31, 2016
1 parent d8d0e2d commit 41d26dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## v.2.6.3 - 31 Oct, 2016

Bugfixes

- Do not change the tls setting to camel_case
- Fix domain handling in combination with the offline queue (2.5.3 regression)

## v.2.6.2 - 16 Jun, 2016

Bugfixes
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,16 +868,16 @@ RedisClient.prototype.internal_send_command = function (command_obj) {
var big_data = false;
var args_copy = new Array(len);

if (process.domain && command_obj.callback) {
command_obj.callback = process.domain.bind(command_obj.callback);
}

if (this.ready === false || this.stream.writable === false) {
// Handle offline commands right away
handle_offline_command(this, command_obj);
return false; // Indicate buffering
}

if (process.domain && command_obj.callback) {
command_obj.callback = process.domain.bind(command_obj.callback);
}

for (i = 0; i < len; i += 1) {
if (typeof args[i] === 'string') {
// 30000 seemed to be a good value to switch to buffers after testing and checking the pros and cons
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function clone (obj) {
var elems = Object.keys(obj);
var elem;
while (elem = elems.pop()) {
if (elem === 'tls') { // special handle tls
copy[elem] = obj[elem];
continue;
}
// Accept camelCase options and convert them to snake_case
var snake_case = elem.replace(/[A-Z][^A-Z]/g, '_$&').toLowerCase();
// If camelCase is detected, pass it to the client, so all variables are going to be camelCased
Expand Down
13 changes: 13 additions & 0 deletions test/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,19 @@ describe('The node_redis client', function () {
});
});

it('keeps the same domain by using the offline queue', function (done) {
client.end(true);
client = redis.createClient();
var testDomain = require('domain').create();
testDomain.run(function () {
client.set('FOOBAR', 'def', function () {
assert.strictEqual(process.domain, testDomain);
done();
});
});
require('domain').create();
});

it('catches all errors from within the domain', function (done) {
var domain = require('domain').create();

Expand Down
6 changes: 5 additions & 1 deletion test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ describe('utils.js', function () {
retryStrategy: false,
nested: {
onlyContainCamelCaseOnce: true
},
tls: {
rejectUnauthorized: true
}
});
assert.strictEqual(Object.keys(a).length, 4);
assert.strictEqual(Object.keys(a).length, 5);
assert.strictEqual(a.option_one_two, true);
assert.strictEqual(a.retry_strategy, false);
assert.strictEqual(a.camel_case, true);
assert.strictEqual(a.tls.rejectUnauthorized, true);
assert.strictEqual(Object.keys(a.nested).length, 1);
});

Expand Down

0 comments on commit 41d26dc

Please sign in to comment.