πŸ”§ Error Fixes
Β· 1 min read

Redis OOM / maxmemory β€” How to Fix It


OOM command not allowed when used memory > 'maxmemory'
MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk.

Redis ran out of its allocated memory and is rejecting write commands.

Fix 1: Increase maxmemory

# Check current setting
redis-cli CONFIG GET maxmemory

# Increase it
redis-cli CONFIG SET maxmemory 512mb

# Permanent: add to redis.conf
maxmemory 512mb

Fix 2: Set an Eviction Policy

# ❌ Default: noeviction β€” rejects writes when full
# βœ… Set a policy to automatically remove old keys
redis-cli CONFIG SET maxmemory-policy allkeys-lru

# Options:
# allkeys-lru β€” evict least recently used keys (most common)
# volatile-lru β€” evict LRU keys with TTL set
# allkeys-random β€” evict random keys
# volatile-ttl β€” evict keys closest to expiration

Fix 3: Add TTL to Keys

# ❌ Keys without TTL stay forever
SET mykey "value"

# βœ… Always set expiration
SET mykey "value" EX 3600  # Expires in 1 hour
SETEX mykey 3600 "value"   # Same thing

Fix 4: Find Large Keys

# Find the biggest keys
redis-cli --bigkeys

# Check memory usage of a specific key
redis-cli MEMORY USAGE mykey

Fix 5: Check What’s Using Memory

# Memory breakdown
redis-cli INFO memory

# Key count by pattern
redis-cli --scan --pattern "session:*" | wc -l
redis-cli --scan --pattern "cache:*" | wc -l

Fix 6: Flush Stale Data

# Delete all keys matching a pattern
redis-cli --scan --pattern "old:*" | xargs redis-cli DEL

# ⚠️ Nuclear option: flush everything
redis-cli FLUSHALL

Related: PostgreSQL Cheat Sheet