From 92b7b6dd6d2e0952b42b6bc0949960b37263d279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Ciparelli?= Date: Thu, 21 Mar 2013 15:57:22 -0300 Subject: [PATCH 1/3] fixes #404 --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e82d2e5f49..df4fe56a6f 100644 --- a/index.js +++ b/index.js @@ -627,6 +627,7 @@ RedisClient.prototype.return_reply = function (reply) { } else { this.pub_sub_mode = true; } + console.log(command_obj); // subscribe commands take an optional callback and also emit an event, but only the first response is included in the callback // TODO - document this or fix it so it works in a more obvious way if (command_obj && typeof command_obj.callback === "function") { @@ -663,7 +664,7 @@ function Command(command, args, sub_command, buffer_args, callback) { } RedisClient.prototype.send_command = function (command, args, callback) { - var arg, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type; + var arg, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type, lcaseCommand; if (typeof command !== "string") { throw new Error("First argument to send_command must be the command name string, not " + typeof command); @@ -693,11 +694,12 @@ 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 and command is sadd, expand it out: + // if the last argument is an array and command is sadd or srem, 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])) { + lcaseCommand = command.toLowerCase(); + if ((lcaseCommand === 'sadd' || lcaseCommand === 'srem') && args.length > 0 && Array.isArray(args[args.length - 1])) { args = args.slice(0, -1).concat(args[args.length - 1]); } From 859d2b1171d860a83044b9c3d7d668bdb44ce478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Ciparelli?= Date: Thu, 21 Mar 2013 17:14:41 -0300 Subject: [PATCH 2/3] removed console.log line --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index df4fe56a6f..3608bcc87b 100644 --- a/index.js +++ b/index.js @@ -627,7 +627,6 @@ RedisClient.prototype.return_reply = function (reply) { } else { this.pub_sub_mode = true; } - console.log(command_obj); // subscribe commands take an optional callback and also emit an event, but only the first response is included in the callback // TODO - document this or fix it so it works in a more obvious way if (command_obj && typeof command_obj.callback === "function") { @@ -710,7 +709,7 @@ RedisClient.prototype.send_command = function (command, args, callback) { return callback(err); } } - + buffer_args = false; for (i = 0, il = args.length, arg; i < il; i += 1) { if (Buffer.isBuffer(args[i])) { From 2e4c178382c7818892379a145f36db630dcd26a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Ciparelli?= Date: Tue, 9 Apr 2013 16:13:25 -0300 Subject: [PATCH 3/3] added tests for #404 --- test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test.js b/test.js index 4b26dca9c9..8f19277c59 100644 --- a/test.js +++ b/test.js @@ -1270,6 +1270,27 @@ tests.SREM = function () { client.scard('set0', last(name, require_number(0, name))); }; + +tests.SREM2 = function () { + var name = "SREM2"; + client.del("set0"); + client.sadd("set0", ["member0", "member1", "member2"], require_number(3, name)); + client.SREM("set0", ["member1", "member2"], require_number(2, name)); + client.smembers("set0", function (err, res) { + assert.strictEqual(res.length, 1); + assert.ok(~res.indexOf("member0")); + }); + client.sadd("set0", ["member3", "member4", "member5"], require_number(3, name)); + client.srem("set0", ["member0", "member6"], require_number(1, name)); + client.smembers("set0", function (err, res) { + assert.strictEqual(res.length, 3); + assert.ok(~res.indexOf("member3")); + assert.ok(~res.indexOf("member4")); + assert.ok(~res.indexOf("member5")); + next(name); + }); +}; + tests.SPOP = function () { var name = "SPOP";