local gid = tostring(ARGV[1]) local limit = tonumber(ARGV[2]) local score = tonumber(ARGV[3]) local zKey = gid .. KEYS[1] local list = redis.call("ZREVRANGE", zKey, limit - 1, limit - 1, "WITHSCORES") local minScore = 0 if #list ~= 0 then minScore = tonumber(list[2]) end if minScore > score then return 1 end local playerId = tostring(ARGV[4]) local fScore = redis.call("ZSCORE", zKey, playerId) if fScore then fScore = tonumber(fScore) if fScore >= score then return 2 end end local recordKey = gid .. KEYS[2] local replayKey = gid .. KEYS[3] local record = tostring(ARGV[5]) local replays = tostring(ARGV[6]) local result = redis.call("ZADD", zKey, score, playerId) list = redis.call("ZREVRANGE", zKey, limit, -1) for i,v in pairs(list) do redis.call("DEL", recordKey .. v, replayKey .. v) end local totalCount = redis.call("ZCARD", zKey) totalCount = tonumber(totalCount) if totalCount > limit then redis.call("ZREMRANGEBYRANK", zKey, 0, totalCount - limit - 1) end redis.call("MSET", recordKey .. playerId, record, replayKey .. playerId, replays) return 0