0
0
Redisquery~5 mins

TTL-based expiry in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
APERSIST session 120
BTTL session 120
CEXPIRE session 120
DSETTTL session 120
What does the TTL command return if a key does not have an expiry set?
A0
B-1
C-2
Dnull
Which command removes the expiry from a key in Redis?
AREMOVEEXPIRE
BEXPIRE 0
CTTL
DPERSIST
If a key's TTL is set to 10 seconds, what happens after 10 seconds?
AThe key is deleted automatically
BThe key's TTL resets to 10 seconds
CThe key becomes read-only
DNothing happens
Which of these commands can you use to check how many seconds remain before a key expires?
ATTL
BEXPIRE
CPERSIST
DGETTTL
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.