Redis easy
Why is the `INCR` command preferred over manual read-and-write logic for counting events like web page views?
- A It is atomic; it ensures the count is correct even if thousands of clients increment it at once.
- B It supports text parsing, allowing Redis to automatically identify numbers inside JSON blobs.
- C It automatically resets the counter to zero every 24 hours to prevent numerical overflow errors.
- D It encrypts the numerical value to prevent malicious users from seeing the total visit traffic.
Answer: A. It is atomic; it ensures the count is correct even if thousands of clients increment it at once.
Because Redis is single-threaded, `INCR` happens in one step. There is no 'race condition' where two clients read '5' and both try to write '6'. One will write '6', and the next will write '7'.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- If the Redis memory limit is reached, what specific behavior is exhibited by the `allkeys-lru` eviction policy?
- What is the defining characteristic of a Redis 'Set' data type compared to a standard Redis 'List'?
- In the context of Redis messaging, what is the functional definition of the 'Pub/Sub' feature?
- How does the Redis background snapshotting process (`BGSAVE`) leverage the operating system's `fork()` mechanism to minimize memory overhead?
- Why does Redis proactively disconnect a Pub/Sub client that exhibits high 'output buffer' usage relative to its ingestion rate?
- How does a 'Sorted Set' (ZSET) manage its internal membership and ordering differently from a plain Set?