Browse Source

Fix small issues with hmset & multi constructor

greenkeeper-update-all
Ruben Bridgewater 9 years ago
parent
commit
38281c20b2
  1. 9
      changelog.md
  2. 5
      index.js
  3. 14
      test/commands/multi.spec.js

9
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

5
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);

14
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')

Loading…
Cancel
Save