0
0
Redisquery~10 mins

SET with expiry (EX, PX) in Redis - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a key with a 10-second expiry using the EX option.

Redis
SET mykey myvalue [1] 10
Drag options to blanks, or click blank then click option'
ANX
BEX
CPX
DXX
Attempts:
3 left
💡 Hint
Common Mistakes
Using PX instead of EX for seconds expiry.
Omitting the expiry option entirely.
2fill in blank
medium

Complete the code to set a key with a 5000-millisecond expiry using the PX option.

Redis
SET session_token abc123 [1] 5000
Drag options to blanks, or click blank then click option'
APX
BNX
CEX
DKEEPTTL
Attempts:
3 left
💡 Hint
Common Mistakes
Using EX instead of PX for millisecond expiry.
Forgetting to specify expiry option.
3fill in blank
hard

Fix the error in the command to set a key with a 20-second expiry using the correct expiry option.

Redis
SET user_id 42 [1] 20
Drag options to blanks, or click blank then click option'
APX
BXX
CEX
DNX
Attempts:
3 left
💡 Hint
Common Mistakes
Using PX instead of EX for seconds expiry.
Using NX or XX which control key existence, not expiry.
4fill in blank
hard

Fill both blanks to set a key with a 3000-millisecond expiry and only if the key does not exist.

Redis
SET cache_key data [1] 3000 [2]
Drag options to blanks, or click blank then click option'
APX
BEX
CNX
DXX
Attempts:
3 left
💡 Hint
Common Mistakes
Using EX instead of PX for milliseconds.
Using XX instead of NX for key existence condition.
5fill in blank
hard

Fill all three blanks to set a key with a 15-second expiry, only if the key exists, and keep the existing TTL if no expiry is given.

Redis
SET config_value 100 [1] 15 [2] [3]
Drag options to blanks, or click blank then click option'
AEX
BPX
CXX
DKEEPTTL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NX instead of XX for key existence condition.
Using PX instead of EX for seconds expiry.
Omitting KEEPTTL when wanting to keep TTL.