🪟 Windows TippsHow to enable and use Leo AI on Brave browser on PC or Phone(16.09.2026 um 04:46 Uhr)
🔧 ProgrammierungDay 11 - N+1 Problem(16.09.2026 um 06:20 Uhr)
🔧 ProgrammierungS3-compatible is a promise with an asterisk(16.09.2026 um 06:20 Uhr)
🪟 Windows TippsHow to enable and use Leo AI on Brave browser on PC or Phone(16.09.2026 um 04:46 Uhr)
🔧 ProgrammierungDay 11 - N+1 Problem(16.09.2026 um 06:20 Uhr)
🔧 ProgrammierungS3-compatible is a promise with an asterisk(16.09.2026 um 06:20 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 2 Min Lesezeit
0

Why Redis Doesn't Implement "True" LRU

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

One question that recently made me rethink cache eviction was:




If Redis uses LRU, why doesn't it maintain a heap (or a perfectly sorted list) of keys?




The answer comes down to optimizing the common case.






The Problem



Imagine a Redis instance with 10 million keys.



If Redis maintained a perfect LRU structure, every cache hit would need to update it:




CODE
GET user:123



Update LRU ordering



Return value






Even though the lookup is O(1), updating a heap would be O(log n), and maintaining a doubly-linked LRU list would still require modifying shared metadata on every single read.



For a cache serving millions of requests per second, that's expensive.






Redis's Approach: Approximate LRU



Instead of maintaining an exact ordering, Redis uses random sampling.



When memory is full and a write arrives:




  1. Randomly sample a small number of keys (default: 5).

  2. Find the least recently used among them.

  3. Evict that key.



At first glance, this seems inaccurate.



What if all 5 sampled keys are hot?



It's possible—but statistically very unlikely for most real-world workloads.






The Clever Optimization: Eviction Pool



Redis goes one step further.



Instead of discarding the remaining sampled keys after each eviction, it keeps the best eviction candidates in a small eviction pool (16 entries internally).



Example:




CODE
Iteration 1
------------
Sample: A B C D E

Pool:
A B C D E

Evict A

Remaining Pool:
B C D E






Need more memory?




CODE
Iteration 2
------------
Sample:
F G H I J

Merge:
B C D E F G H I J

Keep only the best candidates

Evict the worst one






The pool gradually accumulates better eviction candidates while still sampling only a handful of random keys each iteration.






Why This Works



Redis optimizes for the common case:




  • Millions of GETs

  • Relatively few evictions



Instead of paying a maintenance cost on every read, Redis does a small amount of work only when memory is exhausted.



This is a classic systems engineering trade-off:




Accept a near-perfect approximation during rare events to keep the hot path extremely fast.




That's one of the reasons Redis continues to scale so well while delivering cache hit rates that are remarkably close to a true LRU implementation.

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
4 Quellen
CVE-2026-28572 | Google Android 16-qpr2 Tapjacking InstallLaunch.kt OnCreate privileges management
1 Quelle
How to enable and use Leo AI on Brave browser on PC or Phone
1 Quelle
Hacker-Festzelt-Wirt über Pappfiguren: „Wer stört sich an einem asiatischen Touch?“
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Why Redis Doesn't Implement "True" LRU

Thematisch verwandte Begriffe: Redis, Doesnt, Implement, True · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...