learning-it by example

Back to the video

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

  1. 0:00 A cache of 100 keys out of 1,000 caught 58 percent
  2. 0:35 What the Redis docs say
  3. 1:07 Setup
  4. 1:24 A clock you control
  5. 1:42 Set, and evict the least recently used
  6. 2:06 Get, and expire lazily
  7. 2:35 A made-up workload
  8. 3:07 Run it
  9. 4:25 What this does not show
  10. 4:54 Mistakes to avoid
  11. 5:29 My take and next steps
  12. 5:56 Recap

Files

  • cache.py (43 lines)
  • run.py (24 lines)
  • workload.py (22 lines)

Download the code (zip)

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.