Why Redis Is Fast: Build a Cache with Expiry and Eviction
A cache of 100 keys out of about 1,000 answered 58% of made-up requests.
Video #278 ยท How it works, by example
Steps in the video
- 0:00 A cache of 100 keys out of 1,000 caught 58 percent
- 0:35 What the Redis docs say
- 1:07 Setup
- 1:24 A clock you control
- 1:42 Set, and evict the least recently used
- 2:06 Get, and expire lazily
- 2:35 A made-up workload
- 3:07 Run it
- 4:25 What this does not show
- 4:54 Mistakes to avoid
- 5:29 My take and next steps
- 5:56 Recap
Files
- cache.py (43 lines)
- run.py (24 lines)
- workload.py (22 lines)
Tested with
Python 3.12.15
What this does not show
This toy is not Redis: no network, no persistence, exact LRU. The workload is made up, and its skew sets the hit rates.
Sources
Learning IT by Example.