Protocol. Persistence. Replication.

Build Your Own Redis in Rust

A toy Redis server in Rust that parses RESP, restores from RDB, replicates leader-follower state, supports streams, and queues transactional commands.

Implementation docs

Go straight to the detailed implementation docs

Docs overview

Core capabilities

Built around real Redis subsystems

01

Protocol

Parses Redis protocol messages and routes commands through the server runtime.

protocol.rs

02

Persistence

Loads database state from RDB files and restores key metadata.

rdb.rs

03

Replication

Bootstraps replica handshake, full sync, and replicated write flow.

replication_client.rs

04

Streams and transactions

Supports stream operations and queued transactional execution patterns.

cmd.rs

Run it

Start fast, then probe with redis-cli

Master
cargo run -- --dir /some/db/path --dbfilename dump.rdb
Replica
cargo run -- --dir /some/db/path --dbfilename dump.rdb --port 6380 --replicaof "localhost 6379"
Probe
redis-cli PING
redis-cli SET foo bar
redis-cli INFO replication
redis-cli XREAD block 0 streams some_key 1526985054069-0

Implementation map

How the runtime is assembled

protocol.rs

Protocol ingestion

RESP parsing and request framing for incoming client and replication traffic.

server.rs + cmd.rs

Command routing

Connection handling, command dispatch, and transaction orchestration.

storage.rs + rdb.rs

State and restore

In-memory storage backed by RDB parsing and initial database hydration.

replication_client.rs

Replication flow

Replica-side handshake, sync start, and downstream command consumption.

Implementation docs

Follow the code by subsystem

A

Server runtime

Process entry, configuration, listener lifecycle, and shared server state.

Open chapter

B

RESP and storage

RESP parsing and encoding, string storage, expiry model, and stream containers.

Open chapter

C

Persistence and replication

RDB parser internals, handshake flow, full sync, and replica fan-out.

Open chapter

D

Command surface

Command dispatch, stream semantics, transaction replay, and the full chapter map.

Open overview