Complete the code to import the Redis client library.
const redis = require('[1]');
The Redis client library is imported using require('redis') in Express apps.
Complete the code to create a Redis client instance.
const client = redis.createClient({ url: '[1]' });The Redis client connects using a URL starting with redis:// followed by the host and port.
Fix the error in the code to connect the Redis client asynchronously.
await client.[1]();The Redis client uses connect() method to establish the connection asynchronously.
Fill both blanks to set a key with expiration in Redis.
await client.[1]('user:123', 'John Doe', { EX: [2] });
Use set to store a key with a value and expiration time in seconds. The option EX sets the expiration.
Fill all three blanks to retrieve a cached value and handle missing keys.
const value = await client.[1]('user:123'); if (value === [2]) { console.log([3]); }
Use get to retrieve a value. If the key does not exist, Redis returns null. We can log a message like 'Cache miss' to handle this case.