linkyndy
linkyndy

Reputation: 17900

Passing a variable number of arguments to a Redis Lua script

I am using EVAL to pass several arguments to my Lua script. However, the last argument is optional, it may or it may be not passed to EVAL.

How can I check in a Redis Lua script whether an argument is there or not? For example, if ARGV[3] exists or not.

Upvotes: 1

Views: 1756

Answers (2)

Wongfy
Wongfy

Reputation: 67

    redis.call('DEL', KEYS[1])
    local members = {}
    for i = 0, tonumber(ARGV[1]), 1 do
        members[i] = ARGV[1+i]
    end
    redis.call('SADD', KEYS[1], unpack(members))
    return 1

Upvotes: 4

for_stack
for_stack

Reputation: 22936

if ARGV[3] then
    -- user pass in ARGV[3]
else
    -- No ARGV[3]
end

Upvotes: 3

Related Questions