0
0
Expressframework~10 mins

Redis integration for distributed cache in Express - 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.

Express
const redis = require('[1]');
Drag options to blanks, or click blank then click option'
Aredis
Bexpress
Chttp
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' or other unrelated packages instead of 'redis'.
Forgetting to install the redis package before importing.
2fill in blank
medium

Complete the code to create a Redis client instance.

Express
const client = redis.createClient({ url: '[1]' });
Drag options to blanks, or click blank then click option'
Ahttp://localhost:6379
Bftp://localhost:6379
Credis://localhost:6379
Dlocalhost:6379
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http://' instead of 'redis://'.
Omitting the protocol prefix entirely.
3fill in blank
hard

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

Express
await client.[1]();
Drag options to blanks, or click blank then click option'
Aconnect
Bstart
Copen
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'start' or 'open'.
Not awaiting the asynchronous connect call.
4fill in blank
hard

Fill both blanks to set a key with expiration in Redis.

Express
await client.[1]('user:123', 'John Doe', { EX: [2] });
Drag options to blanks, or click blank then click option'
Aset
B3600
Cdel
Dexpire
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' or 'del' instead of 'set' to store data.
Confusing expiration time with milliseconds or other units.
5fill in blank
hard

Fill all three blanks to retrieve a cached value and handle missing keys.

Express
const value = await client.[1]('user:123');
if (value === [2]) {
  console.log([3]);
}
Drag options to blanks, or click blank then click option'
Aset
Bget
Cnull
D'Cache miss'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' instead of 'get' to retrieve data.
Checking for undefined instead of null.
Not handling the cache miss case.