Why Redis is fast, and Redis versus Memcached

In-memory storage, a single-threaded event loop and rich data structures, plus how persistence and replication work.

On the roadmap:Beginner · step 7: Caching basics

Lesson 9 of 23 · 8 min read · quiz · exercise

Why it is fast

  1. Everything lives in memory. No disk seek on the read path.
  2. Simple, efficient data structures (hash tables, skip lists, compact encodings) with predictable costs.
  3. A single-threaded event loop for command execution: no locks between threads, no context switching, and each command runs atomically. I/O multiplexing lets one thread serve thousands of connections.
  4. A lean protocol and in-process memory management.

(Newer versions use extra threads for network I/O, but command execution stays ordered.)

Memory modules in the slots of a computer motherboard: in-memory data is read in nanosecondsImage: Mixabest · Public domain · Source · Wikimedia Commons: Dual-channel DDR memory use 6026

How the pieces fit

Figure SDA-CORE-09-1 · Redis: event loop, memory, persistence and replication · © forcsguy.com

More than a cache

Redis stores typed values:

TypeUse
Stringcached values, counters, flags
Hashobjects with fields (a user profile)
Listqueues, recent items
Setunique members, tags, set maths
Sorted setleaderboards, priority queues, time-ordered data
Othersstreams, bitmaps, HyperLogLog, geospatial

Because operations run on the server, you can increment, push, pop or intersect without a read-modify-write race.

Figure SDA-CORE-09-2 · Redis data types and what they are for · © forcsguy.com

Durability options

Memory is volatile, so Redis offers:

  • Snapshots (RDB): periodic point-in-time dumps. Compact, but recent writes can be lost.
  • Append-only file (AOF): logs every write; replays on restart. Safer, bigger and a little slower.
  • Or none at all when it is purely a cache.

Scaling and availability

  • Replication: a primary copies to replicas (asynchronously), serving reads and enabling failover.
  • Sentinel / managed failover promotes a replica when the primary dies.
  • Cluster: splits keys across nodes by hash slot, for data larger than one machine.

Redis versus Memcached

RedisMemcached
Data typesmanystrings only
Persistenceoptionalnone
Replicationyesnot built in
Threadingone for commandsmulti-threaded
Best forcache plus data structures, queues, countersa very simple, large, pure cache

For most new projects Redis is the more flexible choice. Memcached remains fine for a straightforward cache that must use many CPU cores.

Pitfalls

  • Memory is finite: set a maxmemory and an eviction policy (for example LRU).
  • Avoid slow commands on huge collections.
  • A very hot key still concentrates load on one node.

More on this site

Check your understanding

Question 1 of 3

0 correct so far

Which is a main reason Redis is so fast?

Topics covered in this lesson

All topics

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.