– Token Bucket

– Period is the number of seconds for the token bucket TTL local period = tonumber(ARGV) – The server timestamp for the value delivered local ts = tonumber(ARGV)

– Set the minimum time local min = ts - period

– Bucket Name local bucket_name = KEYS

redis.call(‘ZREMRANGEBYSCORE’, bucket_name, ‘-inf’, min) redis.call(‘ZADD’, bucket_name, ts, ts) redis.call(‘EXPIRE’, bucket_name, period * 5)

return redis.call(‘ZCARD’, bucket_name)