From 124ea082b92b603f27f265d903dce0e745a0c9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Ciparelli?= Date: Fri, 17 Aug 2012 15:23:25 -0300 Subject: [PATCH] fixes #218 by expanding last argument array only for sadd command Also adds a test that uses SADD in caps. Nicely enough, this makes multi_bench.js run just a tiny bit faster :) Signed-off-by: DTrejo --- index.js | 11 +++++------ test.js | 9 ++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 888ee055e3..61cb4e91c5 100644 --- a/index.js +++ b/index.js @@ -676,12 +676,11 @@ RedisClient.prototype.send_command = function (command, args, callback) { throw new Error("send_command: second argument must be an array"); } - // if the last argument is an array, expand it out. This allows commands like this: - // client.command(arg1, [arg2, arg3, arg4], cb); - // and converts to: - // client.command(arg1, arg2, arg3, arg4, cb); - // which is convenient for some things like sadd - if (args.length > 0 && Array.isArray(args[args.length - 1])) { + // if the last argument is an array and command is sadd, expand it out: + // client.sadd(arg1, [arg2, arg3, arg4], cb); + // converts to: + // client.sadd(arg1, arg2, arg3, arg4, cb); + if ((command === 'sadd' || command === 'SADD') && args.length > 0 && Array.isArray(args[args.length - 1])) { args = args.slice(0, -1).concat(args[args.length - 1]); } diff --git a/test.js b/test.js index 4e9289762f..9184680037 100644 --- a/test.js +++ b/test.js @@ -905,7 +905,7 @@ tests.SADD = function () { var name = "SADD"; client.del('set0'); - client.sadd('set0', 'member0', require_number(1, name)); + client.SADD('set0', 'member0', require_number(1, name)); client.sadd('set0', 'member0', last(name, require_number(0, name))); }; @@ -919,6 +919,13 @@ tests.SADD2 = function () { assert.strictEqual(res[0], "member0"); assert.strictEqual(res[1], "member1"); assert.strictEqual(res[2], "member2"); + }); + client.SADD("set1", ["member0", "member1", "member2"], require_number(3, name)); + client.smembers("set1", function (err, res) { + assert.strictEqual(res.length, 3); + assert.strictEqual(res[0], "member0"); + assert.strictEqual(res[1], "member1"); + assert.strictEqual(res[2], "member2"); next(name); }); };