Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis TTL vs "allkeys-lru" eviction policy

Tags:

redis

I have a question on Redis cache's behavior. Kindly clarify -

Say, for a key "xyz" if the TTL is set to 15 minutes. And, if its eviction policy in server level is set to "allkeys-lru". Does expired items(cause of TTL) EXPIRE or WAIT until the memory is full?

like image 928
TuneIt Avatar asked Mar 07 '16 09:03

TuneIt


People also ask

Is Redis LRU or Lfu?

Redis supports various eviction policies including Least Recently Used (LRU), Least Frequently Used (LFU), Random Eviction, and Shorter Time-to-Live (TTL) [20]. Among those policies, LRU replacement is the most commonly chosen policy in industry for both software and hardware caches.

What is Redis default eviction policy?

By default, Amazon ElastiCache for Redis sets the volatile-lru eviction policy for your Redis cluster. When this policy is selected, the least recently used (LRU) keys that have an expiration (TTL) value set are evicted.

Does Redis use LRU cache?

The reason Redis does not use a true LRU implementation is because it costs more memory. However, the approximation is virtually equivalent for an application using Redis.

What is LRU eviction policy?

LRU (or Least Recently Used) is a cache eviction strategy, wherein if the cache size has reached the maximum allocated capacity, the least recently accessed objects in the cache will be evicted.


1 Answers

The eviction policy only applies to what happens when you exceed the max memory. As long as you're within your memory limits, volatile keys will expire when they should be expired.

Once your memory is full, an LRU algorithm kicks in, evicting least recently used keys. In allkeys-lru, it doesn't matter whether a key is expired or not and what is the TTL - the least used items will be evicted. In volatile-lru only expiring keys will be evicted using this algorithm.

like image 163
Not_a_Golfer Avatar answered Sep 24 '22 02:09

Not_a_Golfer