0
0
Redisquery~10 mins

Error handling in clients 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 catch errors when connecting to Redis.

Redis
try {
  const client = redis.createClient();
  await client.connect();
} catch ([1]) {
  console.error('Connection error:', [1]);
}
Drag options to blanks, or click blank then click option'
Aerror
Berr
Cexception
De
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not declared in the catch block.
Leaving the catch parentheses empty.
2fill in blank
medium

Complete the code to listen for Redis client error events.

Redis
client.on('error', function([1]) {
  console.log('Redis error:', [1]);
});
Drag options to blanks, or click blank then click option'
Aerror
Bexception
Ce
Derr
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one used inside the function.
Not passing any parameter to the function.
3fill in blank
hard

Fix the error in the code to properly handle Redis command errors.

Redis
client.get('key', function(err, reply) {
  if ([1]) {
    console.error('Command error:', err);
    return;
  }
  console.log('Value:', reply);
});
Drag options to blanks, or click blank then click option'
Aerr
Berror
Creply
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the reply instead of the error.
Using a wrong variable name for the error.
4fill in blank
hard

Fill both blanks to handle Redis connection errors and close the client.

Redis
client.on('error', function([1]) {
  console.error('Redis error:', [1]);
  client.[2]();
});
Drag options to blanks, or click blank then click option'
Aerr
Berror
Cquit
Ddisconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names in the error handler.
Calling a non-existent method to close the client.
5fill in blank
hard

Fill all three blanks to retry connecting on error with a delay.

Redis
client.on('error', async function([1]) {
  console.error('Error:', [1]);
  await new Promise(resolve => setTimeout(resolve, [2]));
  await client.[3]();
});
Drag options to blanks, or click blank then click option'
Aerr
B1000
Cconnect
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or delay values.
Calling the wrong method to reconnect.