Databases · Middle · Question 74 of 75
Why is Redis INCR a good fit for a simple rate limiter?
- 1It writes the counter to PostgreSQL automatically
- ✓Correct answer: It increments atomically, so concurrent requests from many servers never lose counts; add
EXPIREfor the window - 3It's the only Redis command that supports numbers
Explanation
Redis runs commands one at a time, so INCR has no race. Use a Lua script or SET ... NX EX to set the TTL safely together with the first increment.