DB / Redis / OOM command not allowed
CRITICAL

Redis Out of Memory Policy Rejection

Redis rejected the command because the 'maxmemory' limit was reached and the configured eviction policy ('maxmemory-policy') is set to 'noeviction' or the command would cause memory usage to exceed the limit.

Common Causes

  • The Redis instance has hit its configured 'maxmemory' limit.
  • The 'maxmemory-policy' is set to 'noeviction', which prevents keys from being evicted to make space.
  • An operation (like SET) requires more memory than is currently available under the limit.
  • Memory fragmentation is high, reducing usable memory within the limit.

How to Fix

1 Check Current Memory Configuration

Connect to Redis and check the current memory limit and usage to confirm the issue.

BASH
$ redis-cli INFO memory | grep -E "(used_memory_human|maxmemory_human|maxmemory_policy)"

2 Increase the Maxmemory Limit

Temporarily or permanently increase the memory limit in the Redis configuration file (redis.conf) or via runtime command.

BASH
$ # In redis.conf maxmemory 2gb # Or at runtime (if supported by config) redis-cli CONFIG SET maxmemory 2147483648

3 Change the Eviction Policy

Configure Redis to evict old keys when the limit is reached instead of rejecting commands. 'allkeys-lru' is a common choice.

BASH
$ # In redis.conf maxmemory-policy allkeys-lru # Or at runtime redis-cli CONFIG SET maxmemory-policy allkeys-lru

4 Free Memory by Flushing or Deleting Keys

Manually remove data to free up memory. Use FLUSHDB to clear the current database or DEL to remove specific keys.

BASH
$ # Flush current database (DANGER: deletes all data) redis-cli FLUSHDB # Delete a specific key redis-cli DEL my-large-key

5 Monitor and Optimize Memory Usage

Identify memory-hungry keys and optimize data structures (e.g., use hashes instead of many strings).

BASH
$ # Find largest keys redis-cli --bigkeys # Get memory usage for a specific key pattern redis-cli MEMORY USAGE myhashkey