A Redis clone built from scratch in C++, following the internals of how Redis actually works — TCP sockets, the RESP wire protocol, in-memory storage, key expiry, and an event-driven I/O loop.
I wanted to understand what happens below the API — how a server actually accepts connections, reads bytes off the wire, parses a protocol, and responds. This repo documents that learning process commit by commit.
| Part | What gets built | Status |
|---|---|---|
| 1 | TCP server — socket, bind, listen, accept | ✅ Done |
| 2 | Read loop — recv(), raw RESP bytes visible | ✅ Done |
| 3 | RESP parser — decode arrays, bulk strings | ✅ Done |
| 4 | Commands — PING, ECHO | ✅ Done |
| 5 | In-memory store — SET, GET, DEL | ✅ Done |
| 6 | Key expiry — EX, PX, TTL | ✅ Done |
| 7 | Concurrent clients — epoll event loop | ✅ Done |
g++ -o mini-redis server.cpp
./mini-redisThen in a second terminal:
redis-cli ping # should return PONG
redis-cli set name paritosh
redis-cli get name- Language: C++
- OS: Linux (uses POSIX socket APIs)
- Tested on: Kali Linux
- How TCP servers work at the syscall level (
socket,bind,listen,accept,recv,send) - The RESP (Redis Serialization Protocol) wire format
- How
std::unordered_mapbacks a key-value store - Non-blocking I/O with
epoll - How
std::chronoenables TTL/expiry logic