Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set a key-value pair in Redis using a client library.
Redis
client.[1]('name', 'Alice')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' will only retrieve data, not store it.
✗ Incorrect
The set command stores a key-value pair in Redis.
2fill in blank
mediumComplete the code to retrieve the value of a key from Redis.
Redis
value = client.[1]('name')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' will overwrite data instead of retrieving it.
✗ Incorrect
The get command fetches the value of a given key from Redis.
3fill in blank
hardFix the error in the code to delete a key from Redis.
Redis
client.[1]('name')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' or 'remove' causes errors because Redis expects 'del'.
✗ Incorrect
The correct Redis command to delete a key is del.
4fill in blank
hardFill both blanks to check if a key exists and then delete it if it does.
Redis
if client.[1]('name'): client.[2]('name')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to check existence returns value, not boolean.
✗ Incorrect
Use exists to check if the key is present, then del to delete it.
5fill in blank
hardFill all three blanks to increment a counter only if it exists.
Redis
if client.[1]('counter'): client.[2]('counter') else: client.[3]('counter', 1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'exists' for checking presence.
✗ Incorrect
Check if 'counter' exists, increment it if yes, else set it to 1.