← All posts
Guides· 6 min read

Redis memory usage and eviction: how to monitor it before keys start disappearing

Read INFO memory, understand maxmemory-policy and evicted_keys, spot fragmentation, and set the two alerts that catch Redis memory trouble before the app does.

By , Director of Softuvo Solutions (LinkedIn) · Updated

Redis feels invisible until it isn't. One morning your application slows to a crawl, logs fill with cache misses, and you trace it back to Redis quietly evicting keys for the past six hours. By then, your database is fielding every request that should have been a cache hit. Monitoring Redis memory before it becomes a crisis is one of the highest-leverage things you can do for a production system — and it's not hard once you know what to watch.

Understanding How Redis Uses Memory

Redis keeps all data in RAM, which makes it fast but finite. When memory runs out, Redis doesn't crash — it follows a policy you set (or defaulted into) to decide what to do next. That policy is your eviction policy, and it quietly shapes your cache's behavior under pressure.

Run this command to see your current memory picture at a glance:

redis-cli INFO memory

The fields that matter most are: used_memory_human (how much RAM Redis is actually using), used_memory_peak_human (the high-water mark), mem_fragmentation_ratio (ideally between 1.0 and 1.5), and maxmemory (your configured limit — if this is 0, Redis has no cap and will consume all available RAM).

Eviction Policies — What They Mean in Practice

Redis ships with several eviction policies, and the one you're running determines what happens when maxmemory is hit. Check yours with:

redis-cli CONFIG GET maxmemory-policy

Here's a plain-English summary of the common options:

  • noeviction — Redis returns an error on writes when full. Safe for data you can't lose, but your app needs to handle those errors.
  • allkeys-lru — Evicts the least recently used key across all keys. The most common sensible default for a general cache.
  • volatile-lru — Same as allkeys-lru, but only evicts keys that have a TTL set. Keys without a TTL are never evicted.
  • allkeys-random — Evicts random keys. Rarely the right choice.
  • volatile-ttl — Evicts keys with the shortest remaining TTL first. Good when you want expiring data cleaned up predictably.

If you're running noeviction on a cache that's expected to grow, you're one traffic spike away from write errors. If you're running allkeys-lru but never set TTLs, keys can accumulate indefinitely until pressure forces eviction. Mismatched policy and usage pattern is one of the most common Redis misconfigurations.

The Key Metrics to Track Continuously

One-off checks are a start, but you need ongoing visibility. These are the metrics worth exporting to your monitoring stack — whether that's Prometheus with redis_exporter, Datadog, or a simple cron-based script writing to a time-series DB.

  • used_memory — Raw memory in bytes; alert when it crosses ~80% of maxmemory.
  • evicted_keys — A counter of total keys evicted since startup. A non-zero and rising value means Redis is under memory pressure right now.
  • keyspace_hits and keyspace_misses — Calculate hit rate as hits / (hits + misses). Dropping hit rate alongside rising evictions confirms you're losing useful cache data.
  • mem_fragmentation_ratio — Above 1.5 means Redis is holding fragmented memory it can't fully use; above 2.0 is a signal to consider a restart or MEMORY PURGE.
  • connected_clients — Sudden spikes can explain unexpected memory growth.

To pull eviction stats directly:

redis-cli INFO stats | grep evicted_keys

Setting Up Practical Alerts

Raw metrics are only useful if they trigger action. Here are threshold-based alerts worth configuring:

  • Memory > 75% of maxmemory — Warning. Start investigating before eviction starts.
  • Memory > 90% of maxmemory — Critical. Eviction is likely already happening or imminent.
  • evicted_keys increasing — Any non-zero rate over a 5-minute window deserves attention.
  • Hit rate below 80% — Investigate whether eviction or a cold cache is the cause.
  • mem_fragmentation_ratio above 1.8 — Consider scheduling a maintenance restart or running MEMORY PURGE (Redis 4.0+).

If you're using Prometheus and redis_exporter, a simple alert rule for eviction looks like this:

alert: RedisEvictionOccurring expr: increase(redis_evicted_keys_total[5m]) > 0 for: 5m labels: severity: warning annotations: summary: "Redis is evicting keys"

Diagnosing and Fixing Memory Problems

When you see high memory usage, the first question is: what's actually in there? The MEMORY USAGE command tells you the cost of a specific key:

redis-cli MEMORY USAGE my:key:name

To find the biggest keys across your dataset, use the built-in --bigkeys scanner (run it during off-peak hours — it does scan the full keyspace):

redis-cli --bigkeys

Common fixes once you've diagnosed the problem:

  • Missing TTLs — Use OBJECT ENCODING and OBJECT IDLETIME to find long-lived keys, then add TTLs with EXPIRE.
  • Fragmentation — Run MEMORY PURGE on Redis 4.0+ or schedule a rolling restart on older versions.
  • Oversized values — Revisit your serialization. JSON blobs are often 3–5x larger than MessagePack equivalents.
  • Genuinely outgrowing RAM — Either increase maxmemory, move to a larger instance, or split into multiple Redis instances by data domain.

Making This Easier

Manually stitching together redis-cli, cron jobs, and alert rules works — but it demands ongoing attention that small teams rarely have. Opservo watches your Redis memory trends, flags eviction events in plain English, and surfaces the likely cause alongside a suggested fix, so you're not decoding INFO output at 2am.

Even if you handle all of this yourself, the discipline is the same: export the metrics, set meaningful thresholds, and treat a rising evicted_keys counter as the early warning it is. Redis problems don't announce themselves — they slowly degrade your application until something breaks loudly. Getting ahead of memory pressure is almost always easier than recovering from it.

Related: the same early-warning approach for a database that refuses clients — MySQL "Too many connections": monitor connection usage and fix it.

Read next in the server health and monitoring series: How to Monitor and Alert on Redis Memory Fragmentation Before It Causes Latency Spikes. The whole series is at Server health and monitoring.