Redis C redis/redis

In-memory data structure store used as a database, cache, message broker, and streaming engine.

C 74k stars RSALv2 / SSPLv1 / AGPLv3

About

Redis started as a single programmer's solution to a database bottleneck and grew into one of the most widely deployed pieces of server software ever written. The core codebase is C, written to be read as much as to be run — antirez famously prioritized code clarity, and the source files remain some of the most legible systems code available for study.

Version 8.6.1 is the current stable release. The codebase sits around 150,000 lines of C, but its architecture is unusually approachable: a single-threaded event loop handles all client commands, a small set of hand-tuned data structures backs every data type, and persistence is achieved through two complementary mechanisms that represent distinct tradeoffs. Understanding how these pieces connect gives you a clear mental model of why Redis behaves the way it does under load, after a crash, or at the boundary of memory.

The project was created by Salvatore Sanfilippo (antirez) in 2009, open-sourced shortly after, and has been maintained by Yossi Gottlieb and Oran Agra since antirez stepped back as BDFL in 2020. Redis Inc. funds core development. Since March 2024, the project is no longer BSD-licensed — it uses a tri-license of RSALv2, SSPLv1, and (as of May 2025) AGPLv3, a change that prompted the Linux Foundation to launch the Valkey fork.

Architecture

Event loop (ae.c). A single thread drives everything. aeMain() loops continuously, calling aeProcessEvents() to dispatch I/O events via epoll (Linux) or kqueue (macOS/BSD). No threads means no locks on the hot path — commands execute serially, which makes behavior predictable and the source code traceable without needing to follow concurrent execution.

Data structures. Redis exposes data types — strings, lists, hashes, sets, sorted sets, streams — rather than raw byte values. Internally, each type uses one or more compact representations: dict (a hash table with incremental rehashing), listpack (a tightly packed byte array for small collections), and skiplist (a probabilistic linked structure for sorted sets). The choice of representation switches automatically based on element count and size thresholds.

Persistence: RDB + AOF. Redis forks the process to write a point-in-time snapshot (RDB) — the child writes, the parent continues serving commands using copy-on-write memory pages. The append-only file (AOF) records every write command for finer-grained durability. Both mechanisms can run simultaneously. The tradeoffs between them are explicit and documented in the configuration.

Replication and cluster. Replicas connect to a primary and receive a stream of commands after an initial full sync. Cluster mode shards the keyspace across 16,384 hash slots distributed across nodes, with each node aware of the full slot map.

Start here

If you're new to the Redis codebase, the Grand Tour is the right starting point. It traces execution from main() in server.c through the event loop, command dispatch, and into the data structure and persistence layers. Eight stops, roughly 20–30 minutes of reading. No Redis expertise required — basic C reading ability is enough.

Tours

Getting Started with Your First Contribution to Redis

beginner

Walk through README orientation, the root Makefile, the redis-server main() entry, the runtest Tcl harness, the src/commands/ command-definition pattern, CONTRIBUTING.md and the tri-license, and a pointer to the event loop.

7 stops ~18 min
credisfirst-contributionbuildtcl-tests

Architecture Grand Tour

intermediate

Walk through the Redis event loop, command dispatch, data structures, and persistence layer.

8 stops ~25 min
architectureevent-looppersistencedata-structures

Redis Replication: How Primaries and Replicas Stay in Sync

intermediate

How a replica connects, bootstraps from an RDB snapshot, and stays current through command propagation

7 stops ~25 min
replicationpsynchigh-availabilitydistributed-systems

Redis Streams: A Log With Consumer Groups

intermediate

How Redis stores an append-only log in a radix tree, delivers messages to consumer groups, and tracks unacknowledged entries in the pending entries list

7 stops ~30 min
streamsconsumer-groupsradix-treexaddxreadgroup

Redis Sentinel: Watch, Vote, Fail Over

intermediate

How Sentinel detects failures, elects a leader, and promotes a replica without human intervention

7 stops ~30 min
sentinelhigh-availabilityfailoverraft

Redis Pub/Sub: Channels, Patterns, and Keyspace Notifications

intermediate

How Redis routes messages from publishers to subscribers using channel dicts, glob patterns, and automatic keyspace events

6 stops ~20 min
pubsubmessagingkeyspace-notificationssharded-pubsub

Redis Persistence Deep Dive: RDB, AOF, and the Hybrid

intermediate

How Redis survives a restart: binary snapshots, append-only logs, and the hybrid mode that combines both

8 stops ~30 min
persistencerdbaoffsyncforkdurability

Redis Cluster: Sharding, Gossip, and Failover

advanced

How Redis distributes data across nodes, detects failures through gossip, and promotes replicas without human intervention

7 stops ~30 min
clustergossipshardingfailoverhash-slots

Redis Data Structures & Encoding: How Values Live in Memory

advanced

From raw bytes to skip lists: the memory layouts that make Redis fast and compact

8 stops ~30 min
data-structuresencodingsdsdictskiplistlistpack

RESP Protocol Deep Dive: How Redis Talks Over the Wire

advanced

Eight stops through the parsing, reply, and negotiation code that drives every Redis client connection

8 stops ~30 min
respprotocolwire-formatresp3pipelining

Maintainers

Salvatore Sanfilippo Creator
@antirez

Creator of Redis. Sicilian programmer and security researcher, previously known for creating the Idle Scan TCP technique and hping. Built the first Redis prototype while working on LLOOGG, a real-time analytics product at his company Merzia. Stepped back as BDFL in June 2020, rejoined Redis Inc. in November 2024.

Yossi Gottlieb Core maintainer
@yossigo

Current lead maintainer. Took over day-to-day technical leadership from antirez in 2020. Focused on reliability and the cluster subsystem.

Oran Agra Core maintainer
@oranagra

Co-maintainer alongside Gottlieb. Works on security hardening and the replication system.

Origin Story

Redis: From a Sicilian Startup to a License War

How one programmer's database bottleneck became critical infrastructure for the web -- and what happened when a company had to decide what open source was worth.

Read the full story

Related Projects

Your codebase next

Create code tours for your project

Intraview lets AI create interactive walkthroughs of any codebase. Install the free VS Code extension and generate your first tour in minutes.

Install Intraview Free