SET session:12345 user1 EXPIRE session:12345 5 GET session:12345 # Wait 6 seconds GET session:12345
The key session:12345 is set with value user1 and an expiration of 5 seconds. The first GET returns the value. After waiting 6 seconds, the key expires and the second GET returns nil.
The SET command supports the EX option to set expiration in seconds atomically. SETEX also works but the question asks for one atomic command with TTL as an option.
SET mykey myvalue EXPIRE 30The SET command uses EX or PX to set expiration, not EXPIRE. Option B incorrectly uses EXPIRE as an argument.
EXPIRE updates the TTL of a key without changing its value. SET or SETEX overwrite the value. PERSIST removes TTL.
The SET command without expiration removes any existing TTL. EXPIRE is called before SET, but then SET removes the TTL. Here, the script calls EXPIRE first, then SET, so TTL is lost. The question tests understanding that SET without expiration removes TTL.