1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Arguments passed as arrays should not be mutated. Fixes #866

This commit is contained in:
Ruben Bridgewater
2015-09-24 00:31:55 +02:00
parent f29193a7e0
commit 7be7128b2b
4 changed files with 25 additions and 11 deletions

View File

@@ -1,6 +1,12 @@
Changelog Changelog
========= =========
## v2.0.1 - Sep 24, 2015
Bugfixes:
- Fix argument mutation while using the array notation in combination with keys / callbacks ([#866]). (@BridgeAR)
## v2.0.0 - Sep 21, 2015 ## v2.0.0 - Sep 21, 2015
This is the biggest release that node_redis had since it was released in 2010. A long list of outstanding bugs has been fixed, so we are very happy to present you redis 2.0 and we highly recommend updating as soon as possible. This is the biggest release that node_redis had since it was released in 2010. A long list of outstanding bugs has been fixed, so we are very happy to present you redis 2.0 and we highly recommend updating as soon as possible.

View File

@@ -885,7 +885,7 @@ commands.forEach(function (fullCommand) {
return this.send_command(command, key, arg); return this.send_command(command, key, arg);
} }
if (Array.isArray(arg)) { if (Array.isArray(arg)) {
arg.unshift(key); arg = [key].concat(arg);
return this.send_command(command, arg, callback); return this.send_command(command, arg, callback);
} }
return this.send_command(command, to_array(arguments)); return this.send_command(command, to_array(arguments));
@@ -895,12 +895,12 @@ commands.forEach(function (fullCommand) {
Multi.prototype[command] = function (key, arg, callback) { Multi.prototype[command] = function (key, arg, callback) {
if (Array.isArray(key)) { if (Array.isArray(key)) {
if (arg) { if (arg) {
key.push(arg); key = key.concat([arg]);
} }
this.queue.push([command].concat(key)); this.queue.push([command].concat(key));
} else if (Array.isArray(arg)) { } else if (Array.isArray(arg)) {
if (callback) { if (callback) {
arg.push(callback); arg = arg.concat([callback]);
} }
this.queue.push([command, key].concat(arg)); this.queue.push([command, key].concat(arg));
} else { } else {
@@ -980,12 +980,12 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
var tmp_args, field; var tmp_args, field;
if (Array.isArray(key)) { if (Array.isArray(key)) {
if (args) { if (args) {
key.push(args); key = key.concat([args]);
} }
tmp_args = ['hmset'].concat(key); tmp_args = ['hmset'].concat(key);
} else if (Array.isArray(args)) { } else if (Array.isArray(args)) {
if (callback) { if (callback) {
args.push(callback); args = args.concat([callback]);
} }
tmp_args = ['hmset', key].concat(args); tmp_args = ['hmset', key].concat(args);
} else if (typeof args === "object") { } else if (typeof args === "object") {
@@ -1029,7 +1029,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = function (callback) {
this.wants_buffers = new Array(this.queue.length); this.wants_buffers = new Array(this.queue.length);
// drain queue, callback will catch "QUEUED" or error // drain queue, callback will catch "QUEUED" or error
for (var index = 0; index < this.queue.length; index++) { for (var index = 0; index < this.queue.length; index++) {
var args = this.queue[index].slice(); var args = this.queue[index].slice(0);
var command = args.shift(); var command = args.shift();
var cb; var cb;
if (typeof args[args.length - 1] === "function") { if (typeof args[args.length - 1] === "function") {

View File

@@ -30,8 +30,10 @@ describe("The 'hmget' method", function () {
}); });
}); });
it('allows keys to be specified by passing an array', function (done) { it('allows keys to be specified by passing an array without manipulating the array', function (done) {
client.HMGET(hash, ["0123456789", "some manner of key"], function (err, reply) { var data = ["0123456789", "some manner of key"];
client.HMGET(hash, data, function (err, reply) {
assert.strictEqual(data.length, 2);
assert.strictEqual("abcdefghij", reply[0].toString()); assert.strictEqual("abcdefghij", reply[0].toString());
assert.strictEqual("a type of value", reply[1].toString()); assert.strictEqual("a type of value", reply[1].toString());
return done(err); return done(err);

View File

@@ -148,26 +148,32 @@ describe("The 'multi' method", function () {
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) { it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
var now = Date.now(); var now = Date.now();
var arr = ["multihmset", "multibar", "multibaz"];
var arr2 = ['some manner of key', 'otherTypes'];
var arr3 = [5768, "multibarx", "multifoox"];
client.multi([ client.multi([
["mset", [578, "multibar"], helper.isString('OK')], ["mset", [578, "multibar"], helper.isString('OK')],
[["mset", "multifoo2", "multibar2", "multifoo3", "multibar3"], helper.isString('OK')], [["mset", "multifoo2", "multibar2", "multifoo3", "multibar3"], helper.isString('OK')],
["hmset", ["multihmset", "multibar", "multibaz"]], ["hmset", arr],
[["hmset", "multihmset2", "multibar2", "multifoo3", "multibar3", "test", helper.isString('OK')]], [["hmset", "multihmset2", "multibar2", "multifoo3", "multibar3", "test", helper.isString('OK')]],
["hmset", ["multihmset", "multibar", "multifoo", helper.isString('OK')]], ["hmset", ["multihmset", "multibar", "multifoo", helper.isString('OK')]],
["hmset", [5768, "multibarx", "multifoox"], helper.isString('OK')], ["hmset", arr3, helper.isString('OK')],
['hmset', now, {123456789: "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}], ['hmset', now, {123456789: "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}],
['hmset', 'key2', {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 999}, helper.isString('OK')], ['hmset', 'key2', {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 999}, helper.isString('OK')],
["hmset", "multihmset", ["multibar", "multibaz"]], ["hmset", "multihmset", ["multibar", "multibaz"]],
["hmset", "multihmset", ["multibar", "multibaz"], helper.isString('OK')], ["hmset", "multihmset", ["multibar", "multibaz"], helper.isString('OK')],
]) ])
.hmget(now, 123456789, 'otherTypes') .hmget(now, 123456789, 'otherTypes')
.hmget('key2', ['some manner of key', 'otherTypes']) .hmget('key2', arr2, function noop() {})
.hmget(['multihmset2', 'some manner of key', 'multibar3']) .hmget(['multihmset2', 'some manner of key', 'multibar3'])
.mget('multifoo2', ['multifoo3', 'multifoo'], function(err, res) { .mget('multifoo2', ['multifoo3', 'multifoo'], function(err, res) {
assert(res[0], 'multifoo3'); assert(res[0], 'multifoo3');
assert(res[1], 'multifoo'); assert(res[1], 'multifoo');
}) })
.exec(function (err, replies) { .exec(function (err, replies) {
assert.equal(arr.length, 3);
assert.equal(arr2.length, 2);
assert.equal(arr3.length, 3);
assert.strictEqual(null, err); assert.strictEqual(null, err);
assert.equal(replies[10][1], '555'); assert.equal(replies[10][1], '555');
assert.equal(replies[11][0], 'a type of value'); assert.equal(replies[11][0], 'a type of value');