0
0
Node.jsframework~10 mins

Redis for distributed caching in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Redis client library in Node.js.

Node.js
const redis = require('[1]');
Drag options to blanks, or click blank then click option'
Afs
Bexpress
Credis
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' or other unrelated modules instead of 'redis'.
Forgetting to install the 'redis' package before requiring it.
2fill in blank
medium

Complete the code to create a Redis client using the modern Node.js Redis library.

Node.js
const client = redis.[1]();
Drag options to blanks, or click blank then click option'
Aconnect
BinitClient
CnewClient
DcreateClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' instead of 'createClient'.
Trying to instantiate with 'new redis()' which is not the modern pattern.
3fill in blank
hard

Fix the error in the code to connect the Redis client asynchronously.

Node.js
await client.[1]();
Drag options to blanks, or click blank then click option'
Aconnect
Bstart
Copen
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous connect methods that do not exist.
Forgetting to await the connection.
4fill in blank
hard

Fill both blanks to set a key with a value and an expiration time in Redis.

Node.js
await client.set('[1]', '[2]', { EX: 60 });
Drag options to blanks, or click blank then click option'
AuserToken
BsessionId
C12345
Dabcdef
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up key and value positions.
Using numeric values as keys.
5fill in blank
hard

Fill all three blanks to get a cached value, check if it exists, and log it or a fallback message.

Node.js
const cached = await client.[1]('[2]');
if (cached [3] null) {
  console.log('Cached value:', cached);
} else {
  console.log('No cached value found');
}
Drag options to blanks, or click blank then click option'
Aget
BuserToken
C!==
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==', causing wrong condition.
Using wrong method like 'fetch' instead of 'get'.