Recall & Review
beginner
What is Redis used for in an Express application?
Redis is used as a fast, in-memory data store to cache data and improve performance by reducing database load in an Express app.
Click to reveal answer
beginner
How do you connect Redis to an Express app?
You install a Redis client like the 'redis' npm package, create a Redis client instance, and use it to set and get cached data inside your Express routes or middleware.
Click to reveal answer
intermediate
What does 'distributed cache' mean with Redis?
Distributed cache means Redis stores cached data centrally so multiple app servers can share the same cache, improving speed and consistency across the system.
Click to reveal answer
intermediate
Why use Redis instead of in-memory cache in Express?
Redis keeps cache outside the app process, so cache survives app restarts and can be shared across multiple servers, unlike in-memory cache which is local and temporary.
Click to reveal answer
beginner
Show a simple example of setting and getting a cache value with Redis in Express.
Example:
const redis = require('redis');
const client = redis.createClient();
await client.connect();
app.get('/data', async (req, res) => {
const cached = await client.get('key');
if (cached) return res.send(cached);
const data = 'some data';
await client.set('key', data, { EX: 60 });
res.send(data);
});Click to reveal answer
What npm package is commonly used to connect Redis with Express?
✗ Incorrect
The 'redis' package is the official and commonly used client to connect Redis with Node.js and Express.
Why is Redis considered a good choice for distributed caching?
✗ Incorrect
Redis stores data in-memory and acts as a centralized cache accessible by multiple servers, making it ideal for distributed caching.
What happens if you use in-memory cache inside Express without Redis in a multi-server setup?
✗ Incorrect
In-memory cache is local to each server process, so caches are not shared, leading to inconsistent data across servers.
Which Redis command sets a key with an expiration time in seconds?
✗ Incorrect
The SET command with the EX option sets a key with a value and expiration time in seconds.
In Express, where is Redis caching logic usually placed?
✗ Incorrect
Redis caching is typically done inside Express route handlers or middleware to cache responses or data.
Explain how Redis helps improve performance in an Express app using distributed caching.
Think about how sharing cache between servers helps avoid repeated work.
You got /4 concepts.
Describe the steps to integrate Redis caching in an Express route.
Focus on how to check and set cache in the route.
You got /5 concepts.