0

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 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.