Recall & Review
beginner
What is the purpose of the INCR command in Redis when implementing a rate limiter?
INCR increments the value of a key by one. In rate limiting, it counts the number of requests made by a user or client within a time window.
Click to reveal answer
beginner
Why do we use the EXPIRE command alongside INCR in Redis for rate limiting?
EXPIRE sets a time-to-live (TTL) on the key so that the count resets after a fixed time window, allowing the rate limiter to enforce limits per time period.
Click to reveal answer
intermediate
How does combining INCR and EXPIRE help prevent race conditions in a Redis rate limiter?
By using INCR atomically and setting EXPIRE only when the key is new, Redis ensures accurate counting without conflicts even with concurrent requests.
Click to reveal answer
beginner
What happens if EXPIRE is not set on the Redis key used for rate limiting?
The count will never reset, causing the user to be permanently blocked after reaching the limit once, which is incorrect behavior.
Click to reveal answer
intermediate
Explain the typical request flow for a rate limiter using Redis INCR and EXPIRE.
1. Client sends request.<br>2. Server runs INCR on a key representing the client.<br>3. If key is new, EXPIRE is set to define the time window.<br>4. If count exceeds limit, request is rejected.<br>5. Otherwise, request proceeds.
Click to reveal answer
What does the Redis INCR command do in a rate limiter?
✗ Incorrect
INCR increases the count of requests made by a client, helping track usage.
Why is the EXPIRE command important in Redis rate limiting?
✗ Incorrect
EXPIRE sets a time limit so the count resets, allowing rate limits per time period.
What happens if you call INCR on a non-existing key in Redis?
✗ Incorrect
INCR creates the key with initial value 1 if it does not exist.
How can you ensure EXPIRE is only set once when using INCR for rate limiting?
✗ Incorrect
If INCR returns 1, the key is new, so set EXPIRE once to start the time window.
What is a common problem if EXPIRE is not used in a Redis rate limiter?
✗ Incorrect
Without EXPIRE, counts accumulate indefinitely, blocking users permanently after limit.
Describe how Redis INCR and EXPIRE commands work together to implement a rate limiter.
Think about counting requests and resetting counts after some time.
You got /4 concepts.
Explain the request flow and key management in a Redis-based rate limiter using INCR and EXPIRE.
Focus on how Redis commands control counting and timing.
You got /4 concepts.