mranney/node_redis — pull request #633 by cPu1 (2014-07-23 08:31:31+00:00)
Title: Allow EVAL KEYS and ARGS to be passed as an array

`redis.eval` requires that the client know the KEYS and ARGS that will be passed to the Lua script.
I am using Lua scripts that manipulate a variable number of KEYS and have to use the following code:

`var args = [script, keys.length].concat(keys);`
`redis.eval(args, function (err, res) {
//
});
`

redis.eval should allow calls of the forms (callback optional):
`redis.eval(script, keys, args);`
`redis.eval(script, keys);`
`redis.eval(script); //no args`

To give a concrete example, this function increments the KEYS passed to the script and returns the new values in an array.

function incrementAgentCount (groupIds, domain) {
var groupKeys = groupIds.map(function (groupId) {
return groupId + '@' + domain;
}),
script = "local updated = {};for i = 1, #KEYS do local k = KEYS[i]; updated[i] = redis.call('hincrby', k, 'agents:online', 1);
end;return updated;",
args = [script, groupKeys.length].concat(groupKeys);

mRedis.eval(args, function (err, res) {
//res
});

}