Browse Source

Fix and test for [GH-123]

Passing an Array as as the last argument should expand as users
expect.  The old behavior was to coerce the arguments into Strings,
which did surprising things with Arrays.
gh-pages
Matt Ranney 13 years ago
parent
commit
50d9f8d45e
  1. 10
      index.js
  2. 2
      package.json
  3. 16
      test.js

10
index.js

@ -457,6 +457,7 @@ RedisClient.prototype.return_reply = function (reply) {
} else if (this.monitoring) {
len = reply.indexOf(" ");
timestamp = reply.slice(0, len);
// TODO - this de-quoting doesn't work correctly if you put JSON strings in your values.
args = reply.slice(len + 1).match(/"[^"]+"/g).map(function (elem) {
return elem.replace(/"/g, "");
});
@ -508,6 +509,15 @@ RedisClient.prototype.send_command = function (command, args, callback) {
return;
}
// 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 (Array.isArray(args[args.length - 1])) {
args = args.slice(0, -1).concat(args[args.length - 1]);
}
command_obj = new Command(command, args, false, callback);
if ((!this.ready && !this.send_anyway) || !stream.writable) {

2
package.json

@ -1,5 +1,5 @@
{ "name" : "redis",
"version" : "0.6.5",
"version" : "0.6.7",
"description" : "Redis client library",
"author": "Matt Ranney <mjr@ranney.com>",
"contributors": [

16
test.js

@ -389,7 +389,7 @@ tests.HMSET_BUFFER_AND_ARRAY = function () {
field1 = "buffer",
value1 = new Buffer("abcdefghij"),
field2 = "array",
value2 = [],
value2 = ["array contents"],
name = "HSET";
client.HMSET(key, field1, value1, field2, value2, last(name, require_string("OK", name)));
@ -695,6 +695,20 @@ tests.SADD = function () {
client.sadd('set0', 'member0', last(name, require_number(0, name)));
};
tests.SADD2 = function () {
var name = "SADD2";
client.del("set0");
client.sadd("set0", ["member0", "member1", "member2"], require_number(3, name));
client.smembers("set0", 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);
});
};
tests.SISMEMBER = function () {
var name = "SISMEMBER";

Loading…
Cancel
Save