From 41d26dc0c81b02799cf01eb37390b7c80829e7bb Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 30 Oct 2016 21:29:35 +0100 Subject: [PATCH] Fix domain handling and tls camelCase settings Fixes #1106 Fixes #1103 Closes #1104 --- changelog.md | 7 +++++++ index.js | 8 ++++---- lib/utils.js | 4 ++++ test/node_redis.spec.js | 13 +++++++++++++ test/utils.spec.js | 6 +++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index afeb2239667..e90f258966e 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/index.js b/index.js index a196394ae2b..2f9c2490128 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/lib/utils.js b/lib/utils.js index bc685b9a4f8..e44ed89ea6e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 8f4a53c11b6..e85b3fe347f 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -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(); diff --git a/test/utils.spec.js b/test/utils.spec.js index f6fa8d4e7dd..e036d84167c 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -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); });