Building a tiny version of Redis: RESP, TCP Streams, and Owning Your Data
A key-value store sounds simple: accept a command, look up a key, return a value. The interesting work starts when those commands have to cross a socket. A server needs a wire format, a parser that can handle input arriving in pieces, and a clear answer to the question of who owns the data after a command has been processed. I implemented a tiny version of Redis to make those pieces small enough to see at once. It is a single-threaded C server that speaks a useful subset of Redis’s RESP protocol and supports PING, ECHO, SET, and GET. The implementation is deliberately limited, but it has the same basic shape as a real network service: create a listening socket, accept a connection, parse requests, execute commands, serialize replies, and manage memory that outlives an individual request. ...