๐ฝ Redis and Valkey: cheat sheet
๐จ The analogyA sports club's kit room by the pitch, with labelled cubbies and one quick kit manager handling each request.
๐ The regular explanationAn in-memory key-value server with rich data structures, where one thread runs each command atomically, keys can expire, and memory limits trigger eviction; Valkey is the Linux Foundation fork made in 2024 when Redis changed its licence.
- Coach Maya says a cubby's label, and the kit manager hands over what's inside straight away. No searching, just the label.
- She puts something new in a fresh cubby with its own label. It's ready for anyone who asks for that label.
- Fetching the same kind of thing from the storage shed means a long walk. The kit room is fast because everything is within arm's reach.
- If the kit room floods, whatever was only in the cubbies is gone. The storage shed still has its things.
- The room is back open, but its cubbies start empty and fill up again as people put things in.
- The tally card counts visits. The coach just says "add one", and the manager does it right there.
- The player card has little labelled pockets, so the coach can change just the shirt size and leave the rest alone.
- New jobs go onto the end of the row of hooks. Whoever does the jobs takes them from the front, in order.
- Ana's name tag goes in the bag twice, but the bag only ever holds one of each name. So it counts who turned up, not how many times.
- The leaderboard keeps every name in score order. Asking for the top three is instant, because it's already sorted.
- Both coaches ask the kit manager to add one to the goals tally at the same moment.
- The manager does Maya's request first, from start to finish, and tells her the new number.
- Then Leo's. The tally goes up by two, exactly right, and nobody needed to guard the card.
- Now both coaches do it the wrong way. Each asks for the number to do the sum themselves, and both are told 2.
- Both work out 2 plus 1 and say "make it 3". Two goals went in, but the tally only went up by one.
- Some cubbies have a clear-by tag. Ana's locker pass is cleared in 30 minutes, Ben's count in a minute. The old team sheet has no tag.
- A minute passes. Ben's count is cleared out by itself, so he starts fresh.
- The match report goes in the free cubby. Now all three cubbies are full.
- The club's rule is "never throw anything out", so the manager refuses the score sheet. The room is full.
- The club changes the rule to "clear out whatever nobody has opened for longest". The old team sheet goes, and the score sheet gets its cubby.
- For years the kit room's plan was free for anyone to copy and run, and Coach Maya's club used one of those copies.
- In 2024 the company behind the plan changed the rules, so big centres couldn't freely run new versions for others any more.
- A group of centres took the last freely shared plan and built their own room from it, called Valkey, looked after by a neutral group.
- Maya asks Valkey in exactly the same words, and gets the same answer. She doesn't have to learn anything new.
- Since then the two rooms have each added their own improvements, and the original has made its plan freely available again under a new set of rules.
- The club assistant carries "add one to Ben's request count" to the kit room. It's the third this minute, well under the limit of 100.
- Maya asks for the kit list for match 42. The sign says check the kit room first, but the cubby is empty.
- So the long walk to the storage shed happens, and the answer is left in a cubby with a clear-by tag on the way back.
- The next time anyone asks, it comes straight from the kit room. Nobody walks to the shed.
๐งฉ Key questions
- Two coaches each ask the kit manager to add one to the goals tally at the same moment. What happens?
- The tally goes up by two, because the manager does one request fully, then the other. Nobody can cut in halfway through a request, so both additions count.
- A coach takes the tally card away, adds one at their desk and brings it back, while another coach does the same. What can go wrong?
- Both copy the same old number, so one of the additions is lost. Each request is safe on its own, but the gap between asking for the number and giving it back isn't. Ask the manager to add one instead.
- The kit room is full and the club's rule is never to throw anything out. A coach brings something new. What happens?
- The manager refuses it until space is freed. Clearing out old things only happens if the club chooses that rule.
- Maya's club moves from the original kit room to the Valkey kit room. What does she need to change in how she asks for things?
- Nothing; she asks in the same words, just at the other room. Valkey was built from the same plan, so the cubbies and the words are the same.