5. You want to store a temporary login token in Redis that expires after 5 minutes. Which sequence of commands correctly sets the token and checks its remaining TTL after 3 minutes?
hard
A. SET login_token abc EX 300
SLEEP 180
EXISTS login_token
B. SET login_token abc PX 300
WAIT 180
EXISTS login_token
C. SET login_token abc EX 300
SLEEP 180
TTL login_token
D. SET login_token abc EX 300
WAIT 180
EXISTS login_token
Solution
Step 1: Use SET with EX 300 for 5 minutes expiration
The command SET login_token abc EX 300 sets the token with 300 seconds TTL.
Step 2: Wait 180 seconds (3 minutes) and check TTL
Using SLEEP 180 simulates waiting. Then TTL login_token shows remaining time, confirming token still exists.
Step 3: EXISTS only returns 1 or 0, TTL shows time left
Checking TTL is better to confirm token is still valid and how long it lasts.
Final Answer:
SET login_token abc EX 300
SLEEP 180
TTL login_token -> Option C
Quick Check:
SET with EX + wait + TTL check = correct flow [OK]
Hint: Use SET with EX, wait, then TTL to check remaining time [OK]
Common Mistakes:
Using PX instead of EX for seconds
Using WAIT instead of SLEEP (WAIT waits for replicas, not sleep)
Using EXISTS which only returns existence, not TTL
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.