0
0
Redisquery~5 mins

EXPIRE and TTL for time-to-live in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the EXPIRE command do in Redis?
The EXPIRE command sets a time-to-live (TTL) in seconds on a key. After this time, the key will be automatically deleted.
Click to reveal answer
beginner
How can you check the remaining time before a Redis key expires?
Use the TTL command to see how many seconds remain before the key expires. It returns -1 if the key has no expiration and -2 if the key does not exist.
Click to reveal answer
intermediate
What happens if you set EXPIRE on a key that does not exist?
The EXPIRE command will return 0, meaning it did not set the expiration because the key does not exist.
Click to reveal answer
intermediate
Can you remove the expiration from a Redis key? If yes, how?
Yes, use the PERSIST command to remove the expiration and make the key permanent.
Click to reveal answer
advanced
What is the difference between EXPIRE and PEXPIRE in Redis?
EXPIRE sets the TTL in seconds, while PEXPIRE sets the TTL in milliseconds, allowing more precise expiration times.
Click to reveal answer
What does the TTL command return if a key does not have an expiration?
A-2
B0
C1
D-1
Which command sets a key to expire after a certain number of seconds?
APERSIST
BTTL
CEXPIRE
DGET
If you want to remove the expiration from a key, which command should you use?
APERSIST
BEXPIRE
CTTL
DDEL
What does the EXPIRE command return if the key does not exist?
A1
B0
C-1
D-2
Which command sets the expiration time in milliseconds?
APEXPIRE
BPTTL
CTTL
DEXPIRE
Explain how to set and check the expiration time of a key in Redis.
Think about how you tell Redis to delete a key after some time and how to see how much time is left.
You got /4 concepts.
    Describe how to remove the expiration from a Redis key and what effect it has.
    Consider what happens if you want a key to stay forever after setting an expiration.
    You got /3 concepts.