MINESWEEPER 系统设计
原型文档 · 非正式发布返回游戏 ↗
参考源码设计 v0.8.1

promote_record.lua

参考源码 · docs/account-system/redis/promote_record.lua

lua
-- KEYS[1]: existing verified body key, never a user-supplied path.
-- ARGV[1]: original date's ends_at; ARGV[2]: fixed public_until.
-- Application verifies the DB candidate before calling, and rechecks before commit.
local ends = tonumber(ARGV[1])
local target = tonumber(ARGV[2])
local time = redis.call('TIME')
local now = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
if not ends or not target or ends ~= math.floor(ends) or target ~= math.floor(target)
  or target <= ends then return redis.error_reply('INVALID_DEADLINE') end
if now >= ends then return redis.error_reply('BOARD_FROZEN') end
local expires = redis.call('PEXPIRETIME', KEYS[1])
if expires == -2 then return redis.error_reply('REPLAY_MISSING') end
if expires == -1 or expires > target then return redis.error_reply('INVALID_EXISTING_TTL') end
-- Repeating the same absolute deadline does not slide retention.
redis.call('PEXPIREAT', KEYS[1], target)
return {'ready', tostring(target)}