Skip to content

Commit 38281c2

Browse files
author
Ruben Bridgewater
committed
Fix small issues with hmset & multi constructor
1 parent f26b64d commit 38281c2

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
Changelog
22
=========
33

4+
## v2.x.x - xx, 2015
5+
6+
Bugfixes:
7+
8+
- Fix argument mutation while using the array notation with the multi constructor (@BridgeAR)
9+
- Fix multi.hmset key not being type converted if used with an object and key not being a string (@BridgeAR)
10+
411
## v2.0.1 - Sep 24, 2015
512

613
Bugfixes:
714

8-
- Fix argument mutation while using the array notation in combination with keys / callbacks ([#866]). (@BridgeAR)
15+
- Fix argument mutation while using the array notation in combination with keys / callbacks ([#866](.)). (@BridgeAR)
916

1017
## v2.0.0 - Sep 21, 2015
1118

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ function Multi(client, args) {
860860
var command, tmp_args;
861861
if (Array.isArray(args)) {
862862
while (tmp_args = args.shift()) {
863-
command = tmp_args.shift();
863+
command = tmp_args[0];
864+
tmp_args = tmp_args.slice(1);
864865
if (Array.isArray(command)) {
865866
this[command[0]].apply(this, command.slice(1).concat(tmp_args));
866867
} else {
@@ -989,10 +990,10 @@ Multi.prototype.hmset = Multi.prototype.HMSET = function (key, args, callback) {
989990
}
990991
tmp_args = ['hmset', key].concat(args);
991992
} else if (typeof args === "object") {
992-
tmp_args = ["hmset", key];
993993
if (typeof key !== "string") {
994994
key = key.toString();
995995
}
996+
tmp_args = ["hmset", key];
996997
var fields = Object.keys(args);
997998
while (field = fields.shift()) {
998999
tmp_args.push(field);

test/commands/multi.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@ describe("The 'multi' method", function () {
151151
var arr = ["multihmset", "multibar", "multibaz"];
152152
var arr2 = ['some manner of key', 'otherTypes'];
153153
var arr3 = [5768, "multibarx", "multifoox"];
154+
var arr4 = ["mset", [578, "multibar"], helper.isString('OK')];
154155
client.multi([
155-
["mset", [578, "multibar"], helper.isString('OK')],
156+
arr4,
156157
[["mset", "multifoo2", "multibar2", "multifoo3", "multibar3"], helper.isString('OK')],
157158
["hmset", arr],
158159
[["hmset", "multihmset2", "multibar2", "multifoo3", "multibar3", "test", helper.isString('OK')]],
159160
["hmset", ["multihmset", "multibar", "multifoo", helper.isString('OK')]],
160161
["hmset", arr3, helper.isString('OK')],
161162
['hmset', now, {123456789: "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}],
162163
['hmset', 'key2', {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 999}, helper.isString('OK')],
163-
["hmset", "multihmset", ["multibar", "multibaz"]],
164+
["HMSET", "multihmset", ["multibar", "multibaz"]],
164165
["hmset", "multihmset", ["multibar", "multibaz"], helper.isString('OK')],
165166
])
166167
.hmget(now, 123456789, 'otherTypes')
@@ -174,6 +175,7 @@ describe("The 'multi' method", function () {
174175
assert.equal(arr.length, 3);
175176
assert.equal(arr2.length, 2);
176177
assert.equal(arr3.length, 3);
178+
assert.equal(arr4.length, 3);
177179
assert.strictEqual(null, err);
178180
assert.equal(replies[10][1], '555');
179181
assert.equal(replies[11][0], 'a type of value');
@@ -186,6 +188,14 @@ describe("The 'multi' method", function () {
186188
});
187189
});
188190

191+
it('converts a non string key to a string', function(done) {
192+
// TODO: Converting the key might change soon again.
193+
client.multi().hmset(true, {
194+
test: 123,
195+
bar: 'baz'
196+
}).exec(done);
197+
});
198+
189199
it('allows multiple operations to be performed using a chaining API', function (done) {
190200
client.multi()
191201
.mset('some', '10', 'keys', '20')

0 commit comments

Comments
 (0)