From 38281c20b2bab5feef09c48262c70c0e4d34c20e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 24 Sep 2015 12:08:25 +0200 Subject: [PATCH] Fix small issues with hmset & multi constructor --- changelog.md | 9 ++++++++- index.js | 5 +++-- test/commands/multi.spec.js | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 1f71c40190..cf2e928969 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,18 @@ Changelog ========= +## v2.x.x - xx, 2015 + +Bugfixes: + +- Fix argument mutation while using the array notation with the multi constructor (@BridgeAR) +- Fix multi.hmset key not being type converted if used with an object and key not being a string (@BridgeAR) + ## v2.0.1 - Sep 24, 2015 Bugfixes: -- Fix argument mutation while using the array notation in combination with keys / callbacks ([#866]). (@BridgeAR) +- Fix argument mutation while using the array notation in combination with keys / callbacks ([#866](.)). (@BridgeAR) ## v2.0.0 - Sep 21, 2015 diff --git a/index.js b/index.js index ad753c9a4c..271b6aa5db 100644 --- a/index.js +++ b/index.js @@ -860,7 +860,8 @@ function Multi(client, args) { var command, tmp_args; if (Array.isArray(args)) { while (tmp_args = args.shift()) { - command = tmp_args.shift(); + command = tmp_args[0]; + tmp_args = tmp_args.slice(1); if (Array.isArray(command)) { this[command[0]].apply(this, command.slice(1).concat(tmp_args)); } else { @@ -989,10 +990,10 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) { } tmp_args = ['hmset', key].concat(args); } else if (typeof args === "object") { - tmp_args = ["hmset", key]; if (typeof key !== "string") { key = key.toString(); } + tmp_args = ["hmset", key]; var fields = Object.keys(args); while (field = fields.shift()) { tmp_args.push(field); diff --git a/test/commands/multi.spec.js b/test/commands/multi.spec.js index 58c9eee0f2..f9661393c5 100644 --- a/test/commands/multi.spec.js +++ b/test/commands/multi.spec.js @@ -151,8 +151,9 @@ describe("The 'multi' method", function () { var arr = ["multihmset", "multibar", "multibaz"]; var arr2 = ['some manner of key', 'otherTypes']; var arr3 = [5768, "multibarx", "multifoox"]; + var arr4 = ["mset", [578, "multibar"], helper.isString('OK')]; client.multi([ - ["mset", [578, "multibar"], helper.isString('OK')], + arr4, [["mset", "multifoo2", "multibar2", "multifoo3", "multibar3"], helper.isString('OK')], ["hmset", arr], [["hmset", "multihmset2", "multibar2", "multifoo3", "multibar3", "test", helper.isString('OK')]], @@ -160,7 +161,7 @@ describe("The 'multi' method", function () { ["hmset", arr3, helper.isString('OK')], ['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", "multihmset", ["multibar", "multibaz"]], + ["HMSET", "multihmset", ["multibar", "multibaz"]], ["hmset", "multihmset", ["multibar", "multibaz"], helper.isString('OK')], ]) .hmget(now, 123456789, 'otherTypes') @@ -174,6 +175,7 @@ describe("The 'multi' method", function () { assert.equal(arr.length, 3); assert.equal(arr2.length, 2); assert.equal(arr3.length, 3); + assert.equal(arr4.length, 3); assert.strictEqual(null, err); assert.equal(replies[10][1], '555'); assert.equal(replies[11][0], 'a type of value'); @@ -186,6 +188,14 @@ describe("The 'multi' method", function () { }); }); + it('converts a non string key to a string', function(done) { + // TODO: Converting the key might change soon again. + client.multi().hmset(true, { + test: 123, + bar: 'baz' + }).exec(done); + }); + it('allows multiple operations to be performed using a chaining API', function (done) { client.multi() .mset('some', '10', 'keys', '20')