yoklainterview sim

Database Redis Expiration Eviction Interview Questions

75 verified Database Redis Expiration Eviction interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Redis Expiration EvictionDifficulty 1
Which command sets a time-to-live (in seconds) on an existing Redis key?
  • aTTL key 60
  • bEXPIRE key 60
  • cPERSIST key 60
  • dDEL key 60
Explanation:EXPIRE key seconds sets a TTL on an existing key, after which it will be automatically deleted. TTL only reads the remaining time, PERSIST removes a TTL, and DEL deletes immediately.
Redis Expiration EvictionDifficulty 1
What does TTL key return when the key exists but has no expiration set?
  • a0
  • b-2
  • c-1
  • dAn error
Explanation:TTL returns -1 for a key that exists but has no associated expiration, and -2 if the key does not exist at all. A positive number is the remaining seconds.
Redis Expiration EvictionDifficulty 1
What does TTL key return when the key does not exist at all?
  • a-2
  • b-1
  • c0
  • dnull
Explanation:-2 specifically means the key does not exist. -1 means it exists without a TTL. This distinction matters for correctly branching in application code.
Redis Expiration EvictionDifficulty 1
Which command removes an existing TTL from a key, making it persist forever (until explicitly deleted)?
  • aEXPIRE key -1
  • bTTL key 0
  • cUNSET key
  • dPERSIST key
Explanation:PERSIST key removes the existing expiration on a key, turning it back into a key with no TTL. EXPIRE key -1 actually deletes the key immediately rather than clearing its TTL.
Redis Expiration EvictionDifficulty 2
A key has a TTL set. An application then runs a plain SET key newvalue (without KEEPTTL) to overwrite it. What happens to the TTL?
  • aThe TTL is preserved automatically, since SET only changes the value
  • bThe TTL is removed unless KEEPTTL is passed
  • cThe TTL restarts counting from zero with the same duration
  • dSET is rejected on a key that already has a TTL
Explanation:By default, SET clears any existing TTL on the key, making it persistent. Passing the KEEPTTL option preserves the original expiration instead.
Redis Expiration EvictionDifficulty 2
Which SET option combination sets a string value and gives it a 30-second TTL in a single atomic command?
  • aSET key value followed separately by TTL key 30
  • bSET key value NX 30
  • cSET key value EX 30
  • dSET key value PERSIST 30
Explanation:SET key value EX 30 sets the value and a 30-second TTL atomically in one round trip. PX does the same in milliseconds. TTL is a read-only command with no such argument form.

Test yourself against the 2475-question Database bank.

Start interview