Challenge - 5 Problems
Redis TTL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the TTL after setting EXPIRE?
You run the following Redis commands:
What will
SET session:user123 "active"EXPIRE session:user123 120What will
TTL session:user123 return immediately after?Redis
SET session:user123 "active" EXPIRE session:user123 120 TTL session:user123
Attempts:
2 left
💡 Hint
TTL returns the remaining time in seconds before the key expires.
✗ Incorrect
After setting EXPIRE with 120 seconds, TTL returns the remaining seconds, which is 120 immediately after.
❓ query_result
intermediate2:00remaining
What does TTL return for a key without expiration?
If you run:
and then:
What is the expected output?
SET config:theme "dark"and then:
TTL config:themeWhat is the expected output?
Redis
SET config:theme "dark"
TTL config:themeAttempts:
2 left
💡 Hint
TTL returns -1 if the key exists but has no expiration.
✗ Incorrect
TTL returns -1 when the key exists but does not have an expiration time set.
📝 Syntax
advanced2:00remaining
Which EXPIRE command syntax is correct?
Which of the following Redis commands correctly sets a key to expire in 60 seconds?
Attempts:
2 left
💡 Hint
The EXPIRE command syntax is: EXPIRE key seconds
✗ Incorrect
The correct syntax is EXPIRE followed by the key and then the number of seconds.
❓ query_result
advanced2:00remaining
What happens to TTL after key deletion?
You run:
What will
SET temp:data "123"EXPIRE temp:data 30DEL temp:dataWhat will
TTL temp:data return after deletion?Redis
SET temp:data "123" EXPIRE temp:data 30 DEL temp:data TTL temp:data
Attempts:
2 left
💡 Hint
TTL returns -2 if the key does not exist.
✗ Incorrect
After deleting the key, it no longer exists, so TTL returns -2.
🧠 Conceptual
expert2:00remaining
Why use EXPIRE instead of manual deletion?
Which is the main advantage of using EXPIRE to set a time-to-live on keys instead of manually deleting keys later?
Attempts:
2 left
💡 Hint
Think about automation and resource management.
✗ Incorrect
EXPIRE automates key removal after a set time, helping manage memory efficiently without manual cleanup.