Recall & Review
beginner
What does TTL stand for in Redis?
TTL stands for Time To Live. It is the duration a key remains in Redis before it expires and is automatically deleted.
Click to reveal answer
beginner
How do you set a TTL for a key in Redis?
You use the
EXPIRE command followed by the key and the number of seconds to live. For example: EXPIRE mykey 60 sets a 60-second TTL.Click to reveal answer
beginner
What happens when a key's TTL reaches zero in Redis?
The key is automatically deleted from the database and is no longer accessible.
Click to reveal answer
beginner
How can you check the remaining TTL of a key in Redis?
Use the
TTL command with the key name. It returns the remaining time in seconds before the key expires.Click to reveal answer
intermediate
Can you remove the TTL from a key in Redis? If yes, how?
Yes, you can remove the TTL using the
PERSIST command. This makes the key permanent until deleted manually.Click to reveal answer
What command sets a TTL of 120 seconds on a Redis key named 'session'?
✗ Incorrect
The correct command to set TTL is EXPIRE followed by the key and seconds.
What does the TTL command return if a key does not have an expiry set?
✗ Incorrect
TTL returns -1 if the key exists but has no expiry.
Which command removes the expiry from a key in Redis?
✗ Incorrect
PERSIST removes the TTL, making the key permanent.
If a key's TTL is set to 10 seconds, what happens after 10 seconds?
✗ Incorrect
When TTL reaches zero, Redis deletes the key automatically.
Which of these commands can you use to check how many seconds remain before a key expires?
✗ Incorrect
TTL returns the remaining time to live in seconds.
Explain how TTL-based expiry works in Redis and why it is useful.
Think about how Redis manages temporary data like sessions.
You got /4 concepts.
Describe the commands used to set, check, and remove TTL on Redis keys.
Focus on the three main TTL-related commands.
You got /3 concepts.