redis-doc icon indicating copy to clipboard operation
redis-doc copied to clipboard

Redis Lua API reference - what is the format of the value returned by redis.call()?

Open hans-notifi opened this issue 8 months ago • 0 comments

I've written a script to sum over a series of values in Redis:

local sum = 0
local k
local v
for k,v in pairs(KEYS) do
    local counter_value = redis.call('get', v)
    if (counter_value ~= nil) then
        sum = sum + tonumber(counter_value)
    end
end
return sum

When I run the script with my array of keys (which, if they exist, point to numbers created by the INCR command), I get the error user_script:7: attempt to perform arithmetic on a nil value. This tells me that whatever is being returned from redis.call('get', v) isn't just a bare string or number or nil or anything. The documentation doesn't tell us anything either - it just spits the results of redis.call() directly into the script output.

What is the format of the value returned by redis.call()?

hans-notifi avatar Dec 06 '23 18:12 hans-notifi