Always set an explicit maxmemory ceiling in valkey.conf so Valkey cannot exhaust host RAM and trigger the Linux OOM killer.

Configuring maxmemory and eviction policy#

maxmemory 4gb
maxmemory-policy allkeys-lru

Common eviction policies#

PolicyBehavior when maxmemory is reachedBest for
noeviction (default)Returns errors on write commands; reads continuePersistent data stores where dropping keys is unacceptable
allkeys-lruEvicts least-recently-used keys across the entire datasetGeneral-purpose caching
allkeys-lfuEvicts least-frequently-used keysSkewed cache workloads with hot keys
volatile-lru / volatile-ttlEvicts only keys that have an EXPIRE TTL setMixed cache + persistent keys in the same instance

Inspecting memory & fragmentation#

valkey-cli INFO memory

Key fields to watch:

  • used_memory_human — Memory allocated by Valkey for data.
  • used_memory_rss_human — Resident memory seen by the OS.
  • mem_fragmentation_ratio — used_memory_rss / used_memory. Values around 1.0–1.5 are normal; consistently > 1.5 indicates fragmentation (consider activedefrag yes); < 1.0 means Valkey is swapping to disk.

Finding large keys safely#

Scan for big keys without blocking the server:

valkey-cli --bigkeys -i 0.1

Inspect exact memory usage of a specific key:

valkey-cli MEMORY USAGE my:large:key