-- HYPOTHETICAL Redis 7.4 materialized feature snapshot. -- One key; version is fixed-width 20-digit monotonic sequence PER KEY. -- ARGV: version, JSON payload, absolute expiry Unix milliseconds. if #KEYS ~= 1 or #ARGV ~= 3 then return redis.error_reply('arguments') end local version = ARGV[1] local expiry = tonumber(ARGV[3]) if #version ~= 20 or not string.match(version,'^%d+$') or not expiry or expiry < 1 or expiry > 9007199254740991 or expiry ~= math.floor(expiry) then return redis.error_reply('invalid arguments') end local kind = redis.call('TYPE',KEYS[1]) if type(kind) == 'table' then kind = kind.ok end if kind ~= 'none' and kind ~= 'hash' then return redis.error_reply('wrong key type') end local t = redis.call('TIME') local now = tonumber(t[1])*1000 + math.floor(tonumber(t[2])/1000) if expiry <= now then return 0 end local old = redis.call('HGET',KEYS[1],'version') if old and version <= old then return 0 end redis.call('HSET',KEYS[1],'version',version,'payload',ARGV[2]) redis.call('PEXPIREAT',KEYS[1],expiry) return 1 -- No retained version after key expiry: a late older but unexpired snapshot could -- reappear. Upstream must enforce ordered per-key versioned snapshots and drop -- obsolete event-time windows; rebuild/switch generations after state loss.