0
votes

I have a scenario where a verification need to happen before running a redis command. The command should only be run if verification passes. I am thinking of using lua scripting to do this. The command that needs to be run together with its arguments should be specified as arguments to the lua script.

The logic of this script is of the form:

if verify(KEYS[1], ARGV[1]) then 
    redis.call(ARGV[2], KEYS[2], <the rest of arguments for the command ARGV[2])
done

The number of arguments needed in the redis.call method depends on the command that is executed (ARGV[2]). These arguments are specified to the script through ARGV[3] to ARGV[n], where n >= 3. I would like to understand how these arguments can be passed to the call method.

1

1 Answers

2
votes

You'll need to copy the remainder of arguments to another table and pass that one to the function using unpack. A snippet is worth a thousand words:

local i, t = {}
for i=3, #ARGV do
  t[#t+1] = ARGV[i]
end

if verify(KEYS[1], ARGV[1]) then 
  redis.call(ARGV[2], KEYS[2], unpack(t))
done