Files
mapo-core/MP.RIOC/RedisScript/RedisUpdateScript_v6.lua
T
Samuele Locatelli facd8c0856 Fix solution MP.RIOC
2026-05-08 12:13:12 +02:00

34 lines
903 B
Lua

-- RedisUpdateScript_v6
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 sentinel = tonumber(ARGV[5])
-- Incrementi
redis.call('HINCRBY', key, 'count', countInc)
redis.call('HINCRBYFLOAT', key, 'totalMs', totalMsInc)
-- 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', tostring(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', tostring(newMin))
end
end
return 1