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

EVAL: allow parameters as an array. Close #368.

Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
This commit is contained in:
DTrejo
2013-02-23 22:04:46 -05:00
parent f3c298d088
commit 938c0526a0
3 changed files with 18 additions and 0 deletions

View File

@@ -7,3 +7,8 @@ client.eval("return 100.5", 0, function (err, res) {
console.dir(err);
console.dir(res);
});
client.eval([ "return 100.5", 0 ], function (err, res) {
console.dir(err);
console.dir(res);
});

View File

@@ -1074,6 +1074,10 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
callback = args.pop();
}
if (Array.isArray(args[0])) {
args = args[0];
}
// replace script source with sha value
var source = args[0];
args[0] = crypto.createHash("sha1").update(source).digest("hex");

View File

@@ -309,6 +309,15 @@ tests.EVAL_1 = function () {
assert.strictEqual("d", res[3], name);
});
// test {EVAL - parameters in array format gives same result}
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
assert.strictEqual(4, res.length, name);
assert.strictEqual("a", res[0], name);
assert.strictEqual("b", res[1], name);
assert.strictEqual("c", res[2], name);
assert.strictEqual("d", res[3], name);
});
// prepare sha sum for evalsha cache test
var source = "return redis.call('get', 'sha test')",
sha = crypto.createHash('sha1').update(source).digest('hex');