Reading Building a sliding window rate limiter with Redis, and w/o addressing the actual logic (which may or may not work).
Optimize by:
- Lua seems a much better choice: idiompotent, portable, server-side, less bandwidth, atomic...
- The call to
ZRANGEBYSCORE
seems to be unused, should be commented out if so - Looking at the use of
ZRANGE
, it appears thatZCARD
it what's actually needed
The (untested) Lua snippet: