Module 02 · From Scratch · Redis · with code: Go · about 18 min to read
Continue where you left off ×
Redis: The Map (SET / GET / DEL)
The Map SET GET DEL · Open board
Follows Redis 02: RESP, The Wire Protocol , which turned raw bytes into a parsed command, and hands off to Redis: One Thread, Many Clients .
Before you start. You already have a command in hand,SET name garv: because the wire-protocol stage parsed it out of the raw bytes for you. This lesson answers the question that parsing left open: once you have SET, GET or DEL, where does the data actually live?
The idea in 30 seconds
A database that looks things up instantly is just a machine that computes where the answer lives, instead of searching for it, Luhn’s 1953 trick, run by a computer.
The number is a hash, the shelf it names is a bucket, and SET/GET/DEL are three thin calls onto that shelf.
Two keys landing on the same bucket is a collision. The bucket copes by chaining, one coat hooked behind another.
The load factor, entries per bucket, is the average length of chain a lookup walks, and a high one makes the table slow with no error to warn you.
Growing the table means recomputing every key’s bucket, and doing that all at once is a multi-second stall on the one thread that answers everyone.
Redis avoids the stall by keeping two racks and moving one coat across on every ordinary operation, so the move is invisible and never blocks anyone.
Read the story
Lesson 5 of 117 in From Scratch
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 1953: a phone number too slow to look up Compute the shelf, don’t search for it Redis’s map: three thin calls on one table Two coats, one hook: the collision Ten million coats, and the rack has to double The fix: move one coat at a time The Go shape of it Terms it explains: hash, bucket, collision, chain, load factor, incremental rehashing.
Review From Scratch
Mark as read Saved in this browser, and to your account when you sign in.