Introduction

  • Why build Redis? Redis exposes you to basic data structures and system programming (mainly network programming), both of which are overlooked by most developers. You can study 2 important subjects in 1 project.
  • Why from scratch? A quote from Richard Feynman: “What I cannot create, I do not understand”. Reading about things often just gives you an illusion of knowledge. Learn deeper by doing!
  • Why C? C was, is, and will be widely used for system programming and infrastructure software. And C is unavoidable for learning low-level stuff. Learn C today and you’ll appreciate in the future.
  • Why a book? The real Redis project is a large code base built with lots of effort. The book isolates the core concepts and guides you through small steps.

Table of Contents

Part 1. Getting Started

  1. Introduction
  2. Socket Programming Concepts
  3. TCP Server and Client
  4. Protocol Parsing
  5. The Event Loop and Nonblocking IO
  6. The Event Loop Implementation
  7. Basic Server: get, set, del

Part 2. Essential Topics

  1. Data Structure: Hashtables
  2. Data Serialization
  3. The AVL Tree: Coding & Testing
  4. Sorted Set From AVL Tree
  5. The Event Loop and Timers
  6. The Heap Data Structure and the TTL
  7. The Thread Pool and Asynchronous Tasks

Source Code

https://build-your-own.org/redis/src.tgz

PDF/EPUB and Paperback Editions

The book is available for purchase.

Book Cover

I have curated a list of books that are highly relevant for people who intend to DIY their own Redis.

Beej’s Guide to Network Programming.
[Amazon] [Web]
A comprehensive guide and reference to network programming. It’s a great supplement for coding your own networked apps, as the Redis book doesn’t cover all the details of socket programming.
The Linux Programming Interface by Michael Kerrisk.
[Amazon] [Web]
The socket API is only a subset of the Linux API interface. You will probably need to become familiar with the other parts, such as IOs, threads and processes, signals, and etc, if you are developing apps for Linux.
The C Programming Language by K&R.
[Amazon]
Are you scared of C, but still want to follow the project? No problem. This classic book is great for picking up C quickly, whether you are a beginner or an experienced developer.