Node.js Course
Node.js
/
Intermediate

Redis

Definition

Remote Dictionary Server. An open-source, in-memory, key-value data store used as a database, cache, message broker, and queue.

Explain Like I'm New

Standard databases (like MongoDB or PostgreSQL) save data to a Hard Drive. Hard drives are safe, but slow. Redis saves data entirely in RAM (Memory). RAM is volatile (wiped if the server restarts), but it is insanely, blazingly fast. Because it's so fast, developers use Redis as the middleman Cache sitting in front of the main database.

Real World Example

Storing User Sessions or JWT Blacklists. Because every single API request requires checking if the user is authenticated, doing a slow SQL query on every request destroys performance. Storing session data in Redis allows sub-millisecond authentication.

Common Use Cases

  • •High-speed caching
  • •Session management
  • •Pub/Sub real-time messaging
  • •Leaderboards

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Does Redis store data on a Hard Drive or in RAM?

intermediate

  • Why not just use a JavaScript Object `const cache = {}` instead of Redis?

Flash Cards

Question

Where does it store data?

Click to reveal answer
Answer

In RAM (Memory).

Question

Why not a simple JS Object?

Click to reveal answer
Answer

If you scale your Node app horizontally across 4 servers, they do not share JS Objects. Server 1's cache is empty even if Server 2 is full. Redis acts as a centralized cache that all 4 servers connect to, sharing the same fast memory.