From 9b1d262cdf0a214cb1628341edfb3692f87a8a86 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 4 Sep 2015 15:21:59 +0200 Subject: [PATCH] Accept hmset being used without a callback. Closes #694 --- index.js | 2 +- test/commands/hmset.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 12a407abd2..151b998220 100644 --- a/index.js +++ b/index.js @@ -996,7 +996,7 @@ RedisClient.prototype.HMGET = RedisClient.prototype.hmget; RedisClient.prototype.hmset = function (args, callback) { var tmp_args, tmp_keys, i, il, key; - if (Array.isArray(args) && typeof callback === "function") { + if (Array.isArray(args)) { return this.send_command("hmset", args, callback); } diff --git a/test/commands/hmset.spec.js b/test/commands/hmset.spec.js index e30669d00e..a4d77dfc01 100644 --- a/test/commands/hmset.spec.js +++ b/test/commands/hmset.spec.js @@ -45,6 +45,42 @@ describe("The 'hmset' method", function () { }); }); + it('allows a numeric key without callback', function (done) { + client.HMSET(hash, 99, 'banana', 'test', 25); + client.HGETALL(hash, function (err, obj) { + assert.equal(obj['99'], 'banana'); + assert.equal(obj['test'], '25'); + return done(err); + }); + }); + + it('allows an array without callback', function (done) { + client.HMSET([hash, 99, 'banana', 'test', 25]); + client.HGETALL(hash, function (err, obj) { + assert.equal(obj['99'], 'banana'); + assert.equal(obj['test'], '25'); + return done(err); + }); + }); + + it('allows an array and a callback', function (done) { + client.HMSET([hash, 99, 'banana', 'test', 25], helper.isString('OK')); + client.HGETALL(hash, function (err, obj) { + assert.equal(obj['99'], 'banana'); + assert.equal(obj['test'], '25'); + return done(err); + }); + }); + + it('handles object-style syntax without callback', function (done) { + client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"}); + client.HGETALL(hash, function (err, obj) { + assert.equal(obj['0123456789'], 'abcdefghij'); + assert.equal(obj['some manner of key'], 'a type of value'); + return done(err); + }) + }); + afterEach(function () { client.end(); });