builds / redis / stage-3SHEET 3 / 6 · REV ASIGN IN
ASSEMBLY DIAGRAM — YOUR REDISSCALE: LEARNING
clientthe outside worldPORT JACK✓ builtRESP CODEC✓ builtMEMORY BANK⚙ buildingINTERLOCKstage 4CLOCK UNITstage 5FLIGHT RECORDERstage 6
BUILTUNDER CONSTRUCTIONNOT YET IMAGINED INTO EXISTENCE
STAGE 3 · THE MEMORY BANK

The Memory Bank

The machine finally remembers.

What you're wiring up

A key-value store at this stage is honestly just a Go map guarded behind three verbs — and that's the point: the hard parts of a database are never the map, they're everything around it (protocol before, concurrency and durability after).

This stage also introduces the discipline of exact protocol semantics: GET of a missing key returns the null bulk string, not an error. SET returns +OK. DEL returns an integer count. Redis's real behavior is the spec.

Assembly steps

[ 01 ]
Add a store type wrapping map[string]string with Get/Set/Del methods; wire SET key value → +OK and GET key → bulk string.
hint

Make the store its own type even though it's trivial — Stages 4–6 all attach to it (lock, clock, recorder).

[ 02 ]
Return $-1\r\n for GET of a never-set key. SET over an existing key silently replaces.
[ 03 ]
Implement DEL key [key...] → integer count of keys that existed, and EXISTS key [key...] → integer count.
hint

DEL a a where a exists once returns :1 — count deletions, not arguments.

[ 04 ]
Validate arity: GET with no args, SET with one → -ERR wrong number of arguments.
hint

The harness checks the '-ERR wrong number' prefix; the connection must survive the error.

Go deeper (after it passes)

Pairs with DDIA M3 — Build Your Own Storage Engine (this is its first half) and Clean Code M4 — Hide the Guts.