wildduck/lib/lua/cachedcounter.lua
Andris Reinman bf878eda1f
fix: ZMS 226 (#817)
* Use async for mailbox folder cache operations instead of doing it in the background

* Promise fix

* Treat negative key as no counter value
2025-05-23 13:27:59 +03:00

20 lines
454 B
Lua

local key = KEYS[1];
local increment = tonumber(ARGV[1]) or 0;
local ttl = tonumber(ARGV[2]) or 0;
if redis.call("EXISTS", key) == 1 then
redis.call("INCRBY", key, increment);
local sum = tonumber(redis.call("GET", key)) or 0;
if sum < 0 then
redis.call("DEL", key);
return nil;
end
-- extend the life of this counter by ttl seconds
redis.call("EXPIRE", key, ttl);
return sum;
else
return nil;
end