Files
mapo-core/MP.RIOC/RedisScript/RedisUpdateScript_v5.lua
T
2026-05-11 10:11:58 +02:00

36 lines
964 B
Lua

-- RedisUpdateScript_v5
local key = KEYS[1]
local countInc = tonumber(ARGV[1]) or 0
local totalMsInc = tonumber(ARGV[2]) or 0
local newMax = tonumber(ARGV[3])
local newMin = tonumber(ARGV[4])
local noReply = tonumber(ARGV[5])
local sentinel = tonumber(ARGV[6])
-- Incrementi
redis.call('HINCRBY', key, 'count', countInc)
redis.call('HINCRBYFLOAT', key, 'totalMs', totalMsInc)
redis.call('HINCRBY', key, 'noReply', noReply)
-- MAX
local currentMaxStr = redis.call('HGET', key, 'maxMs')
local currentMax = tonumber(currentMaxStr)
if newMax ~= nil and newMax < sentinel then
if currentMax == nil or newMax > currentMax then
redis.call('HSET', key, 'maxMs', newMax)
end
end
-- MIN
local currentMinStr = redis.call('HGET', key, 'minMs')
local currentMin = tonumber(currentMinStr)
if newMin ~= nil and newMin < sentinel then
if currentMin == nil or newMin < currentMin then
redis.call('HSET', key, 'minMs', newMin)
end
end
return 1