0
0
Redisquery~5 mins

SET with expiry (EX, PX) in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AMilliseconds
BMinutes
CSeconds
DHours
Which Redis SET option sets expiry in milliseconds?
APX
BEX
CNX
DXX
What happens if you set a key with SET and EX 5, then set it again without expiry?
AThe key keeps the original expiry
BThe command fails
CThe key expires immediately
DThe key expiry is removed
Can you use both EX and PX options together in one SET command?
ANo, it causes an error
BYes, to set two expiries
CYes, PX overrides EX
DNo, but it sets the longer expiry
Which command sets key 'token' with value 'xyz' to expire in 500 milliseconds?
ASET token xyz EX 500
BSET token xyz PX 500
CSET token xyz EX 0.5
DSET token xyz PX 5
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.