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?
✗ Incorrect
TTL returns -1 when the key exists but has no expiration set.
Which command sets a key to expire after a certain number of seconds?
✗ Incorrect
EXPIRE sets the time-to-live in seconds for a key.
If you want to remove the expiration from a key, which command should you use?
✗ Incorrect
PERSIST removes the expiration, making the key permanent.
What does the EXPIRE command return if the key does not exist?
✗ Incorrect
EXPIRE returns 0 if the key does not exist.
Which command sets the expiration time in milliseconds?
✗ Incorrect
PEXPIRE sets the expiration time in milliseconds.
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.