local time = redis.call('TIME') local now = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000) redis.call('ZREMRANGEBYSCORE', KEYS[1], '-inf', now) if redis.call('ZCARD', KEYS[1]) >= tonumber(ARGV[1]) then return 0 end redis.call('ZADD', KEYS[1], now + tonumber(ARGV[2]), ARGV[3]) -- Long async leases and short chat leases share the user bucket. -- A chat admission must never shorten a running async task's lease container. if redis.call('PTTL', KEYS[1]) < tonumber(ARGV[2]) then redis.call('PEXPIRE', KEYS[1], ARGV[2]) end return 1