Keys, TTL & Data Types — Series 3

Preview — 3 of 10 questions

A key was set with SETEX session:42 3600 "data", giving it a 1-hour expiry. What does PERSIST session:42 do?

AIt removes the key's expiration entirely — the key reverts to being permanent (no TTL) and stays in Redis until explicitly deleted, exactly undoing whatever EXPIRE/SETEX/PEXPIRE had set
BIt deletes the key immediately, as if the TTL had just expired
CIt resets the TTL back to its original 3600-second value
DIt pauses the countdown without removing it, resuming from where it left off on the next write to that key

Given SET stock 50, what does DECRBY stock 3 return, and what happens to stock afterward?

AIt returns 47 — DECRBY key n atomically subtracts n from the integer stored at key and returns the new value, exactly mirroring INCRBY's behavior in the opposite direction (DECR key is the n = 1 shorthand, matching INCR)
BIt returns 50 (the value before decrementing) and leaves stock unchanged
CIt errors, since Redis integers can only be incremented, never decremented
DIt returns -3, treating the operation as if stock started at 0

EXPIRE key 3600 sets a TTL of 3600 seconds from now. How do EXPIREAT and PEXPIRE differ from it?

AEXPIREAT key timestamp sets the key to expire at a specific absolute Unix timestamp (rather than a relative number of seconds from now) — useful when the exact expiration moment is computed elsewhere and needs to be set precisely, rather than recalculated as "seconds from now" each time. PEXPIRE key milliseconds is like EXPIRE, but with millisecond precision instead of whole seconds
BEXPIREAT and PEXPIRE are exact synonyms for EXPIRE, provided only for compatibility with older client libraries
CEXPIREAT only works on hash fields, never on top-level keys
DPEXPIRE removes a key's TTL entirely, the opposite of setting one

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.