DEV Community

The Practical Developer
The Practical Developer

Posted on Originally published at practicaldevblog.blogspot.com

Redis Explained: The In-Memory Store That Makes Everything Faster

Introduction

Redis is an in-memory data store: it keeps data in RAM instead of on disk, which makes it roughly a hundred times faster than a disk database for simple operations — but also means it is not where your permanent data should live alone. Redis is the accelerator you bolt onto a real database, and it powers caching, sessions, leaderboards, and queues across the modern web.

Caching: the job Redis is famous for

The most common Redis job is caching: storing the result of an expensive database query so the next request doesn't repeat it.

User requests homepage
  → Check Redis for "homepage:en"
  → Found? Return it instantly (milliseconds)
  → Not found? Query Postgres, store the result in Redis
    with a 60-second expiry, return it
Enter fullscreen mode Exit fullscreen mode

Expiry is the key idea: cached data gets a time-to-live (TTL), after which Redis deletes it and the next request refreshes it from the real database. Stale-for-a-minute data is a fine trade for a homepage that loads instantly, and TTLs are what keep a cache honest.

Data structures, not just keys and values

Redis is more than a simple key-value store — it has data structures built for specific jobs:

  • Strings — simple values, counters (INCR for page views or rate limits)
  • Hashes — objects with fields, perfect for user sessions
  • Lists — queues: push jobs on one end, workers pop from the other
  • Sets and sorted sets — unique members, and leaderboards ranked by score

A leaderboard, for example, is one sorted set: add a player with a score, and Redis keeps the ranking for you — no sorting code, no extra queries.

The rule: complement, never replace

Redis data lives in memory, so a restart can lose it unless persistence is configured — and even then, Redis is not designed to be your only copy of important data. The pattern that works: Postgres or MongoDB holds the truth, Redis holds a fast, disposable copy plus the jobs (sessions, queues, rate limits) where speed matters more than permanence. Used that way, Redis makes everything around it feel instant.

Takeaway

Memory-speed storage, expiry-based caching, purpose-built data structures, and one rule: Redis accelerates your real database, it does not replace it. Add it when slowness appears, not before — and when you do, the speed difference is immediately obvious.

Originally published at https://practicaldevblog.blogspot.com/2026/10/redis-explained-in-memory-store-that.html

Top comments (0)