Created
August 28, 2018 12:32
-
-
Save florentchauveau/18fb5279db0eace78b4828e8282aa56b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Redis script to get the size of a token bucket | |
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260 | |
-- (c) Florent CHAUVEAU <[email protected]> | |
local ts = tonumber(ARGV[1]) | |
local key = KEYS[1] | |
-- remove tokens < min (older than now() -1s) | |
local min = ts -1 | |
redis.call('ZREMRANGEBYSCORE', key, '-inf', min) | |
return redis.call('ZCARD', key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment