Recall & Review
beginner
What does the EX option do in the Redis SET command?
The EX option sets the expiration time for the key in seconds. After this time, the key will be automatically deleted.
Click to reveal answer
beginner
How is PX different from EX in the Redis SET command?
PX sets the expiration time in milliseconds, while EX sets it in seconds.
Click to reveal answer
beginner
Write a Redis command to set key 'session' with value 'abc123' that expires in 10 seconds.
SET session abc123 EX 10
Click to reveal answer
intermediate
What happens if you set a key with SET and an expiry, and then set it again without expiry?
The key will be updated with the new value and the expiry will be removed, so it will not expire unless set again.
Click to reveal answer
intermediate
Can you use both EX and PX options together in a single SET command?
No, you can only use one expiry option at a time: either EX (seconds) or PX (milliseconds). Using both will cause an error.
Click to reveal answer
What unit of time does the EX option use in Redis SET command?
✗ Incorrect
EX sets the expiration time in seconds.
Which Redis SET option sets expiry in milliseconds?
✗ Incorrect
PX sets the expiration time in milliseconds.
What happens if you set a key with SET and EX 5, then set it again without expiry?
✗ Incorrect
Setting a key again without expiry removes any previous expiry.
Can you use both EX and PX options together in one SET command?
✗ Incorrect
Using both EX and PX together causes an error.
Which command sets key 'token' with value 'xyz' to expire in 500 milliseconds?
✗ Incorrect
PX 500 sets expiry to 500 milliseconds.
Explain how to set a key with an expiration time in Redis using the SET command.
Think about how you tell Redis to delete a key automatically after some time.
You got /4 concepts.
What happens if you set a key with expiry and then overwrite it without expiry? Why is this important?
Consider what happens to the timer when you update the key without expiry.
You got /3 concepts.