Browse Source

Merge pull request #1166 from NodeRedis/fix-bugs

Fix domain and camelCase bug
master
Ruben Bridgewater 8 years ago
committed by GitHub
parent
commit
39c88206ca
  1. 7
      changelog.md
  2. 8
      index.js
  3. 4
      lib/utils.js
  4. 2
      test/connection.spec.js
  5. 13
      test/node_redis.spec.js
  6. 6
      test/utils.spec.js

7
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

8
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

4
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

2
test/connection.spec.js

@ -371,7 +371,7 @@ describe('connection tests', function () {
if (err.code === 'ENETUNREACH') { // The test is run without a internet connection. Pretent it works
return done();
}
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message), err.message);
// The code execution on windows is very slow at times
var add = process.platform !== 'win32' ? 15 : 200;
var now = Date.now();

13
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();

6
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);
});

Loading…
Cancel
Save