0
0
Redisquery~20 mins

Redis with Node.js (ioredis) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis with Node.js Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Redis command sequence using ioredis?
Consider the following Node.js code using ioredis:
const Redis = require('ioredis');
const redis = new Redis();

await redis.set('count', 5);
const result = await redis.incr('count');
console.log(result);

What will be printed to the console?
Redis
const Redis = require('ioredis');
const redis = new Redis();

await redis.set('count', 5);
const result = await redis.incr('count');
console.log(result);
A6
BError: value is not an integer
C1
D5
Attempts:
2 left
💡 Hint
The INCR command increases the integer value stored at key by one.
📝 Syntax
intermediate
2:00remaining
Which option correctly sets a hash field using ioredis?
You want to set the field 'name' to 'Alice' in the hash stored at key 'user:1'. Which of the following code snippets is correct?
Aawait redis.hset('user:1', ['name', 'Alice']);
Bawait redis.hset('user:1', {name: 'Alice'});
Cawait redis.hset('user:1', 'name', 'Alice');
Dawait redis.hset('user:1', 'name:Alice');
Attempts:
2 left
💡 Hint
hset takes key, field, and value as separate arguments.
optimization
advanced
2:00remaining
Which approach is best to retrieve multiple keys efficiently with ioredis?
You need to get the values of keys 'key1', 'key2', and 'key3'. Which option is the most efficient?
Aawait redis.pipeline().get('key1').get('key2').get('key3').exec();
Bawait redis.mget('key1', 'key2', 'key3');
Cawait Promise.all([redis.get('key1'), redis.get('key2'), redis.get('key3')]);
Dawait redis.get('key1'); await redis.get('key2'); await redis.get('key3');
Attempts:
2 left
💡 Hint
Pipelining batches commands to reduce round-trip time.
🔧 Debug
advanced
2:00remaining
Why does this ioredis code throw an error?
Given this code:
const Redis = require('ioredis');
const redis = new Redis();

redis.set('foo', 'bar');
const value = await redis.get('foo');
console.log(value);

It throws: SyntaxError: await is only valid in async function. Why?
Redis
const Redis = require('ioredis');
const redis = new Redis();

redis.set('foo', 'bar');
const value = await redis.get('foo');
console.log(value);
ABecause redis.set is missing await.
BBecause redis.get returns undefined.
CBecause Redis client is not connected.
DBecause await is used outside an async function.
Attempts:
2 left
💡 Hint
await can only be used inside async functions.
🧠 Conceptual
expert
2:00remaining
What happens if you call redis.del('key') on a non-existing key?
Using ioredis, you run:
const result = await redis.del('nonexistent');
console.log(result);

What will be printed?
Redis
const result = await redis.del('nonexistent');
console.log(result);
A0
B1
Cnull
DError: key does not exist
Attempts:
2 left
💡 Hint
DEL returns the number of keys removed.