1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

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.
This commit is contained in:
Matt Ranney
2011-07-30 17:21:25 -07:00
parent 6d9298e418
commit 50d9f8d45e
3 changed files with 26 additions and 2 deletions

View File

@@ -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) {