Redis easy
You need to cache a user session to ensure it is automatically cleared after 1 hour. Which Redis feature enables this?
- A Cron Jobs: Setting up a background system script to scan and delete old user records every hour.
- B Garbage Collection: Relying on the native jemalloc allocator to reclaim unused memory segments.
- C TTL (Time To Live): Configuring an expiration timer that triggers a delete when it hits zero.
- D Manual Deletion: Forcing the application layer to track timestamps and delete keys voluntarily.
Answer: C. TTL (Time To Live): Configuring an expiration timer that triggers a delete when it hits zero.
You can set a timeout on any key (e.g., `EXPIRE session:123 3600`). Once the timer hits zero, Redis marks the key as expired and reclaims the memory, either lazily or through active sampling.
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?