pub const INVALIDATION_SCRIPT: &str = r#"local function parse_safe_integer(raw)
if not string.match(raw, "^%d+$") then return nil end
local value = tonumber(raw)
if not value or value > 9007199254740991 then return nil end
return value
end
local future_buffer_ms = parse_safe_integer(ARGV[1])
if not future_buffer_ms or future_buffer_ms < 0 or future_buffer_ms > 31536000000 then
return redis.error_reply("ERR invalid DialCache future buffer")
end
local invalidated_at_ms = parse_safe_integer(ARGV[2])
if not invalidated_at_ms or invalidated_at_ms > 9007199254740991 - future_buffer_ms then
return redis.error_reply("ERR invalid DialCache invalidatedAtMs")
end
local proposed_watermark = invalidated_at_ms + future_buffer_ms
local raw_watermark = redis.pcall("GET", KEYS[1])
if type(raw_watermark) == "table" and raw_watermark.err then
if not string.match(raw_watermark.err, "^WRONGTYPE ") then return raw_watermark end
raw_watermark = false
end
local current_watermark = 0
if raw_watermark then
local parsed_watermark = parse_safe_integer(raw_watermark)
if parsed_watermark then current_watermark = parsed_watermark end
end
local watermark = math.max(current_watermark, proposed_watermark)
local current_ttl_ms = -2
if raw_watermark then current_ttl_ms = redis.call("PTTL", KEYS[1]) end
local desired_ttl_ms = math.max(7200000, watermark - invalidated_at_ms + 3600000 + 60000)
if current_ttl_ms > desired_ttl_ms then desired_ttl_ms = current_ttl_ms end
local encoded_watermark = string.format("%.0f", watermark)
if current_ttl_ms == -1 then
redis.call("SET", KEYS[1], encoded_watermark)
else
redis.call("SET", KEYS[1], encoded_watermark, "PX", desired_ttl_ms)
end
return 1"#;Expand description
The version-1 wire invalidation transition, byte-identical to the Go
InvalidationScript (a unit test pins this against go/redis_adapter.go).
TypeScript’s INVALIDATE_CACHE_SCRIPT is the same Lua with different
whitespace and a comment, so its EVALSHA digest differs; every port
self-heals through the EVAL fallback, so mixed-language clusters need no
shared script cache.
Redis Lua numbers exactly represent the accepted safe-integer domain.
Invalid arguments return before GET/repair; wrong-type keys alone are
repairable read failures.