Preparing your workspace
Production Redis requires choosing the right persistence, availability, memory, security, and monitoring strategy for the workload.
Redis can be used as a cache or as an important data service, and the operational strategy should match that role. Persistence options can provide recovery for appropriate workloads, while replication and managed high-availability solutions can improve resilience. Memory is a finite resource, so eviction policies and key expiration matter. Production environments should restrict network access, protect credentials, monitor memory and latency, and track command usage and connected clients. The application should also decide what happens if Redis becomes unavailable rather than assuming it will always be reachable.
A learning platform may use Redis as a cache and rate limiter while keeping PostgreSQL as the source of truth, allowing the application to recover by rebuilding cache data if Redis is temporarily unavailable.
const cached = await redis.get('course:c1');
if (cached) {
return JSON.parse(cached);
}
const course = await loadCourseFromDatabase('c1');
try {
await redis.set(
'course:c1',
JSON.stringify(course),
'EX',
300
);
} catch (error) {
console.error('Redis cache write failed', error);
}
return course;The application uses Redis when available but can still return database data when the cache write fails.