0
0
Redisquery~10 mins

SETNX for set-if-not-exists 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 only if it does not exist.

Redis
SETNX mykey [1]
Drag options to blanks, or click blank then click option'
Avalue
BEX
CNX
DPX
Attempts:
3 left
💡 Hint
Common Mistakes
Using expiration options like EX or PX instead of the value.
Confusing SETNX with SET command options.
2fill in blank
medium

Complete the command to set key 'user' with value 'Alice' only if it does not exist.

Redis
SETNX [1] Alice
Drag options to blanks, or click blank then click option'
Aname
Buser
Cusername
Duser_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different key name than 'user'.
Confusing the key with the value.
3fill in blank
hard

Fix the error in the command to set key 'session' with value 'abc123' only if it does not exist.

Redis
SETNX session [1]
Drag options to blanks, or click blank then click option'
ASET
B'abc123'
Csession
Dabc123
Attempts:
3 left
💡 Hint
Common Mistakes
Adding quotes around the value.
Using the key name as the value.
4fill in blank
hard

Fill both blanks to set key 'config' with value 'enabled' only if it does not exist, and check the result.

Redis
SETNX [1] [2]
Drag options to blanks, or click blank then click option'
Aconfig
Benabled
Csettings
Ddisabled
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value.
Using wrong key or value names.
5fill in blank
hard

Fill all three blanks to set key 'flag' with value 'true' only if it does not exist, then get the key.

Redis
SETNX [1] [2]
GET [3]
Drag options to blanks, or click blank then click option'
Aflag
Btrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys in SETNX and GET.
Using wrong values like 'false'.