Skip to content

Commit 75b3fdb

Browse files
committed
Merge pull request #822 from fintura/hmset
Accept hmset being used without a callback. Closes #694
2 parents 03e696b + 9b1d262 commit 75b3fdb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ RedisClient.prototype.HMGET = RedisClient.prototype.hmget;
996996
RedisClient.prototype.hmset = function (args, callback) {
997997
var tmp_args, tmp_keys, i, il, key;
998998

999-
if (Array.isArray(args) && typeof callback === "function") {
999+
if (Array.isArray(args)) {
10001000
return this.send_command("hmset", args, callback);
10011001
}
10021002

test/commands/hmset.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ describe("The 'hmset' method", function () {
4545
});
4646
});
4747

48+
it('allows a numeric key without callback', function (done) {
49+
client.HMSET(hash, 99, 'banana', 'test', 25);
50+
client.HGETALL(hash, function (err, obj) {
51+
assert.equal(obj['99'], 'banana');
52+
assert.equal(obj['test'], '25');
53+
return done(err);
54+
});
55+
});
56+
57+
it('allows an array without callback', function (done) {
58+
client.HMSET([hash, 99, 'banana', 'test', 25]);
59+
client.HGETALL(hash, function (err, obj) {
60+
assert.equal(obj['99'], 'banana');
61+
assert.equal(obj['test'], '25');
62+
return done(err);
63+
});
64+
});
65+
66+
it('allows an array and a callback', function (done) {
67+
client.HMSET([hash, 99, 'banana', 'test', 25], helper.isString('OK'));
68+
client.HGETALL(hash, function (err, obj) {
69+
assert.equal(obj['99'], 'banana');
70+
assert.equal(obj['test'], '25');
71+
return done(err);
72+
});
73+
});
74+
75+
it('handles object-style syntax without callback', function (done) {
76+
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"});
77+
client.HGETALL(hash, function (err, obj) {
78+
assert.equal(obj['0123456789'], 'abcdefghij');
79+
assert.equal(obj['some manner of key'], 'a type of value');
80+
return done(err);
81+
})
82+
});
83+
4884
afterEach(function () {
4985
client.end();
5086
});

0 commit comments

Comments
 (0)