What are Redis Memory Eviction Policies and how do you choose the right one?

Asked 19 hours ago 32 views

0

When Redis reaches its maximum allocated memory limit defined by the maxmemory configuration setting, it invokes an eviction policy to determine which keys should be removed to make room for new write operations.

Key Eviction Strategies

  • allkeys-lru: Evicts the least recently used keys across all keys, regardless of TTL settings.
  • volatile-lru: Evicts least recently used keys that have an explicit expiration time configured.
  • noeviction: Returns write errors when memory capacity is reached (default policy).

You can configure the active maxmemory-policy dynamically using Redis CLI parameters:

-- Set maximum memory cap to 2 Gigabytes
CONFIG SET maxmemory 2gb

-- Change memory eviction policy to volatile-lru
CONFIG SET maxmemory-policy volatile-lru

-- Inspect current maxmemory-policy setting
CONFIG GET maxmemory-policy

0 Answers


Write Your Answer