redis-doc
redis-doc copied to clipboard
Redis Lua API reference - what is the format of the value returned by redis.call()?
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()
?