Module 1: Redis Fundamentals - Laying the Groundwork
redis-cli: Introduction to the Redis command-line interface for interacting with the Redis server. Basic commands like PING, SET, GET, DEL.SET, GET).LPUSH, RPUSH, LPOP, RPOP, LRANGE).SADD, SMEMBERS, SREM).HSET, HGET, HGETALL).ZADD, ZRANGE, ZREVRANGE).SETBIT, GETBIT, BITCOUNT).PFADD, PFCOUNT).XADD, XRANGE).redis-server, redis-cli, PING, SET, GET, DEL, LPUSH, RPUSH, LPOP, RPOP, LRANGE, SADD, SMEMBERS, SREM, HSET, HGET, HGETALL, ZADD, ZRANGE, BITCOUNT, PFADD, PFCOUNT, XADD, XRANGE.redis-cli to experiment with basic commands and all the fundamental data types.Module 2: Core Redis Operations - Mastering Data Manipulation
SET, GET, MSET, MGET, INCR, DECR, APPEND.LINDEX, LINSERT, LLEN, LREM, LTRIM, RPOPLPUSH.SISMEMBER, SPOP, SRANDMEMBER, SINTER, SUNION, SDIFF.HEXISTS, HINCRBY, HKEYS, HVALS, HDEL.ZREM, ZINCRBY, ZCOUNT, ZRANK, ZREVRANK, ZSCORE.EXPIRE: Set a timeout for a key in seconds.TTL: Get the remaining time-to-live of a key.PTTL: Get the remaining time-to-live in milliseconds.PERSIST: Remove the expiration from a key.KEYS: Find all keys matching a given pattern (use with caution in production due to performance implications).SCAN: Iteratively scan the keyspace, avoiding blocking the server.SUBSCRIBE: Subscribe to one or more channels.PUBLISH: Send a message to a specific channel.UNSUBSCRIBE: Unsubscribe from one or more channels.MSET, MGET, INCR, DECR, APPEND, LINDEX, LINSERT, LLEN, LREM, LTRIM, RPOPLPUSH, SISMEMBER, SPOP, SRANDMEMBER, SINTER, SUNION, SDIFF, HEXISTS, HINCRBY, HKEYS, HVALS, HDEL, ZREM, ZINCRBY, ZCOUNT, ZRANK, ZREVRANK, ZSCORE, EXPIRE, TTL, PTTL, PERSIST, KEYS, SCAN, SUBSCRIBE, PUBLISH, UNSUBSCRIBE.redis-cli. Experiment with key expiration and the Pub/Sub model.Module 3: Integrating Redis with Node.js - Connecting Your Backend
Setting up Redis Client: Instructions and code examples for connecting to Redis from a Node.js application using popular client libraries:
ioredis: Recommended for its performance and feature set.redis: The original Node.js Redis client.Caching API Responses: Example of creating a middleware function in Express to cache API responses in Redis based on the request URL.JavaScript
`// Installation: npm install ioredis express const Redis = require('ioredis'); const redis = new Redis(); const express = require('express'); const app = express();
const cacheMiddleware = async (req, res, next) => {
const key = api:${req.originalUrl};
const cachedResponse = await redis.get(key);
if (cachedResponse) {
return res.status(200).send(cachedResponse);
}
res.sendResponse = res.send;
res.send = (body) => {
redis.setex(key, 300, body); // Cache for 5 minutes
res.sendResponse(body);
};
next();
};
app.get('/api/users', cacheMiddleware, async (req, res) => { // Simulate fetching data from database await new Promise(resolve => setTimeout(resolve, 1000)); res.json([{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Smith' }]); });
app.listen(3000, () => console.log('Server started on port 3000'));`
Caching Computed Data: Examples of caching the results of expensive computations in Redis.