How it works · in-memory data store

How Redis works

One big dictionary held in memory, answered by a single loop that takes one command at a time.

Think of it like this. One very fast clerk at one desk. Nobody else touches the filing cabinet, so nothing ever needs a lock.

  1. The event loop Waits on thousands of connections at once, and wakes when any of them has something to say. src/ae.c
  2. Networking Reads bytes from a client, cuts them into a command and its arguments, and queues the reply. src/networking.c
  3. The server Looks the command up in a table, checks it is allowed, and runs it. src/server.c
  4. The keyspace The dictionary itself: every key, and the value it points to. src/db.c
  5. The data types Strings, lists, hashes, sorted sets: one file of commands for each. src/t_string.c
  6. Persistence Saves memory to disk, as a snapshot or as a log of every write. src/rdb.c

Follow one thing through: A client sends SET name lin

  1. The connection has bytes waiting, so the event loop calls the function that reads them.src/ae.c
  2. The bytes are parsed into three pieces: SET, name, lin.src/networking.c
  3. The server finds SET in its command table and calls it.src/server.c
  4. The SET command stores the value under the key.src/t_string.c
  5. The key goes into the dictionary for the current database.src/db.c
  6. The reply “OK” is queued for the client. The write is also passed to the log on disk, if that is switched on, and to any replicas.src/aof.c

The clever bit: Growing the table without stopping

When the dictionary gets full it needs a bigger table, and moving millions of keys at once would freeze every client. So Redis keeps two tables and moves a few buckets on each operation. Lookups check both until the move is finished. Nobody waits, and the cost of growing is spread over thousands of commands.

src/dict.c

Words you’ll meet

single-threaded
Commands run one after another on one thread, so two can never clash.
RDB
A snapshot of everything in memory, written to one file.
AOF
A log of every write. Replaying it rebuilds the data.
eviction
What Redis throws away when memory is full. It samples a few keys and removes the best candidate.

Good questions to ask next

Open Redis in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.

Take Redis apart yourself.

Free and open source. Nothing to install, no account.

Ideas inside it

More projects, taken apart

Written by hand from the code as it was on 2026-12-03 (commit ff28c55). Redis belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.