Skip to content

Commit

Permalink
EVAL: allow parameters as an array. Close #368.
Browse files Browse the repository at this point in the history
Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
  • Loading branch information
DTrejo committed Feb 24, 2013
1 parent f3c298d commit 938c052
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/eval.js
Expand Up @@ -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);
});
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions test.js
Expand Up @@ -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');
Expand Down

0 comments on commit 938c052

Please sign in to comment.