Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
-- Redis script to get the size of a token bucket
-- see
-- (c) Florent CHAUVEAU <>
local ts = tonumber(ARGV[1])
local key = KEYS[1]
-- remove tokens < min (older than now() -1s)
local min = ts -1'ZREMRANGEBYSCORE', key, '-inf', min)
return'ZCARD', key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment