Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new Redis client using ioredis.
Redis
const Redis = require('ioredis'); const redis = new [1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'redis' instead of 'Redis' causes an error.
Trying to use 'client' without importing it.
✗ Incorrect
The Redis class from the ioredis package is used to create a new Redis client instance.
2fill in blank
mediumComplete the code to set a key 'name' with value 'Alice' in Redis.
Redis
await redis.[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 not store the value.
Using 'del' deletes keys, not sets them.
✗ Incorrect
The set command stores a key-value pair in Redis.
3fill in blank
hardFix the error in the code to get the value of key 'name' from Redis.
Redis
const value = await redis.[1]('name');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' instead of 'get' causes the value to be overwritten.
Using 'del' deletes the key instead of reading it.
✗ Incorrect
The get command retrieves the value stored at the given key.
4fill in blank
hardFill both blanks to delete the key 'name' and check if it still exists.
Redis
await redis.[1]('name'); const exists = await redis.[2]('name');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' to delete a key does not work.
Using 'set' to check existence is incorrect.
✗ Incorrect
The del command deletes a key, and exists checks if the key is still present.
5fill in blank
hardFill all three blanks to increment a counter, get its value, and then reset it to zero.
Redis
await redis.[1]('counter'); const count = await redis.[2]('counter'); await redis.[3]('counter', 0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' to increment does not work.
Using 'del' instead of 'set' to reset deletes the key.
✗ Incorrect
incr increases the counter by 1, get retrieves its value, and set resets it to zero.