What Is Redis

Redis is a tool that stores data in your computer's memory (RAM) instead of on a hard disk. Because RAM is much faster than a disk, Redis can read and write data at extremely high speed. Apps use Redis when they need quick access to data — often within a millisecond.

The Ticket Counter Analogy

Imagine a busy train station. Every passenger asks a counter clerk for their ticket status. The clerk has two options:

Option A – Fetch from a Filing Cabinet (Slow)
┌─────────────┐         ┌──────────────────┐
│  Passenger  │──ask──▶ │     Clerk        │
└─────────────┘         │  walks to room,  │
                        │  opens cabinet,  │
                        │  finds file      │
                        │  (~10 seconds)   │
                        └──────────────────┘

Option B – Read from a Sticky Note on the Desk (Fast)
┌─────────────┐         ┌──────────────────┐
│  Passenger  │──ask──▶ │     Clerk        │
└─────────────┘         │  glances at      │
                        │  sticky note     │
                        │  (~0.1 seconds)  │
                        └──────────────────┘

Redis is the sticky note. Your database is the filing cabinet. Redis keeps the most-needed data right at hand so your app does not wait.

What Makes Redis Different from a Regular Database

A regular database like MySQL stores data on disk and reads it each time you ask. Redis stores data in RAM, so the data is already loaded and ready. Redis also uses simple key-value pairs — like a dictionary — instead of complex tables with rows and columns.

Regular Database (Disk-Based)
┌──────────┐    read request    ┌──────────┐    fetch     ┌──────────┐
│   App    │───────────────────▶│   DB     │─────────────▶│   Disk   │
│          │◀───────────────────│  Engine  │◀─────────────│  Storage │
└──────────┘    slow response   └──────────┘   slow disk  └──────────┘

Redis (Memory-Based)
┌──────────┐    read request    ┌──────────┐
│   App    │───────────────────▶│  Redis   │  (data already in RAM)
│          │◀───────────────────│          │
└──────────┘  ultra-fast reply  └──────────┘

Where Apps Actually Use Redis

Caching Web Pages

When thousands of users visit the same page, the server builds that page fresh every time if Redis is not involved. With Redis, the server builds the page once, saves the result in Redis, and serves it from memory for every other visitor. The server saves huge amounts of processing time.

Session Storage

When you log into a website, the server creates a session — a record that says "this browser is logged in." Redis stores these sessions so the server can check login status in under a millisecond without touching the main database.

Real-Time Leaderboards

Games and apps with live rankings use Redis Sorted Sets. Redis can rank a million players by score and return the top ten results almost instantly.

Message Queues

Background jobs — like sending emails or processing orders — wait in a Redis queue. Workers pick tasks from the queue one by one. This keeps the main app fast while heavy work happens in the background.

Key Points

  • Redis stores data in RAM, not on disk, making reads and writes extremely fast.
  • Redis uses a key-value model — you store a value under a name and retrieve it by that name.
  • Common uses include caching, session management, real-time rankings, and message queues.
  • Redis works alongside a main database — it does not replace it.

Leave a Comment