Databases 2 min read

Understanding Redis Memory Eviction: 6 Policies Explained

When Redis reaches its maxmemory limit, it can use one of six eviction policies—volatile‑lru, allkeys‑lru, volatile‑random, allkeys‑random, volatile‑ttl, or noeviction—to decide which keys to remove, with defaults and configurable sampling influencing performance and accuracy.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Understanding Redis Memory Eviction: 6 Policies Explained

When Redis's maximum usable memory is exhausted, it follows one of six configurable eviction policies.

volatile-lru : Uses the LRU algorithm to delete keys that have an expiration set.

allkeys-lru : Uses the LRU algorithm to delete any key, regardless of expiration.

volatile-random : Randomly deletes keys with an expiration set.

allkeys-random : Randomly deletes any key.

volatile-ttl : Deletes the key with the nearest expiration among keys that have an expiration set.

noeviction : Does not evict; write operations that exceed memory return an error.

The default policy is noeviction , configured via maxmemory-policy .

For LRU‑based policies, Redis samples a small number of keys (default 5 ) and evicts the least recently used among them. The sample size is set by maxmemory-samples and can be adjusted; larger samples improve accuracy but increase CPU usage, while smaller samples are faster but less precise.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cacheredisdatabasesmemory eviction
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.