The smallest possible Redis-shaped server. It binds a port, accepts one connection at a time, reads bytes, and writes the same bytes back.
Before we worry about the Redis protocol (RESP), data structures, or persistence, we prove that the network layer works. If the echo server can hold a conversation with nc, the foundation is solid.
make 01-tcp-echoIn another terminal:
nc localhost 6380
> hello
< hello
> ping
< ping- The server prints
[recv]for every chunk of data - Closing nc with Ctrl+D prints
[conn] disconnected - A second client cannot connect while the first is active. Try opening two
ncsessions to see the queue.
| File | Purpose |
|---|---|
server.py |
The runnable echo server |
GUIDE.md |
How sockets work, why this is single-client |
EXERCISES.md |
Variations to stretch the idea |
Step 2 adds the RESP wire format so the server understands real Redis commands instead of raw bytes.