Databases 10 min read

Redis Memory OOM Diagnosis: Causes, Investigation Steps, and Practical Commands

This article explains why Redis can report out‑of‑memory (OOM) errors even with small datasets, describes the two types of OOM, outlines memory‑consumption categories, presents systematic troubleshooting methods, and provides a collection of useful Redis commands for diagnosing and resolving memory‑related issues.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Redis Memory OOM Diagnosis: Causes, Investigation Steps, and Practical Commands

Background

Many users encounter OOM errors in Redis even when the data size appears small. Redis OOM can occur in two ways: (1) the Redis process exceeds the physical memory of the operating system and is killed by the OS, and (2) Redis exceeds the maxmemory configuration, causing the server‑side OOM. When OOM happens, the process stays alive, reads are still possible, but writes are blocked, and memory‑eviction policies such as allkeys-lru or allkeys-lfu may evict a large number of keys, sharply reducing cache hit rates.

Redis Memory Consumption Breakdown

The memory used by Redis can be divided into several parts:

Object memory – stores all business data (strings, hashes, etc.).

Client memory – input and output buffers of connected clients; this area is not limited by maxmemory and is a primary focus during troubleshooting.

Replication backlog – a fixed‑size buffer that holds write commands for replicas.

Redis internal memory – metadata such as the key‑space dictionary.

AOF buffer – used for AOF persistence and rewrite; usually negligible.

Problems Caused by Memory OOM

Redis can read but cannot write.

When the maxmemory-policy is set to a non‑default value (e.g., noeviction), massive key eviction or expiration can degrade query performance.

Investigation Ideas

Note: In the examples below the default maxmemory is set to 1 GB unless otherwise stated.

Is the data volume too large?

Use redis-benchmark to continuously insert data and monitor memory usage. When OOM occurs, used_memory will exceed maxmemory. The overhead.total metric includes memory used by replication buffers, client buffers, and other metadata.

Is the client input buffer problematic?

Generate input‑buffer pressure with redis-benchmark. After a few seconds the OOM state appears, and the total input‑buffer consumption can reach several gigabytes, far beyond the maxmemory limit.

# 关键参数解释
-d 表示每个set值的大小,单位为字节
-c 启多少个连接

Identify the connection consuming the most input buffer memory and kill it if necessary:

# 例如杀掉上图中 id=51421 的连接
127.0.0.1:9999> CLIENT KILL ID 51421
(integer) 1

Is the replication backlog problematic?

Set the backlog size to a large value (e.g., 800 MB) and run a benchmark. When the backlog fills, Redis cannot write further data even though the actual data size is modest.

Is the client output buffer problematic?

Output‑buffer pressure is rare but can happen when the monitor command is used. Enable monitor, run a benchmark, and observe that the total output‑buffer memory quickly exceeds maxmemory, leading to OOM.

Practical Commands

Simulating Redis Load

# 1. 持续给Redis灌数据
redis-benchmark -p 9999 -t set -r 100000000 -l
# 2. 模拟输入缓冲区过大
redis-benchmark -p 9999 -q -c 10 -d 102400000 -n 10000000 -r 50000 -t set
# 3. 模拟输出缓冲区过大
redis-benchmark -p 9999 -t get -r 5000000 -n 10000000 -d 100 -c 1000 -P 500 -l

Common Redis Memory Inspection Commands

# 1. 快速查看Redis内存是否够用
redis-cli -p 9999 info memory | egrep '(used_memory_human|maxmemory_human|maxmemory_policy)'
# 2. 检查复制积压缓冲区使用情况
redis-cli -p 9999 memory stats | egrep -A 1 '(total.allocated|replication.backlog)'
# 3. 检查客户端输入缓冲区内存使用总量
redis-cli -p 9999 client list | awk 'BEGIN{sum=0}{sum+=substr($12,6);sum+=substr($13,11)}END{print sum}'
# 4. 检查客户端输入缓冲区各客户端连接的内存情况
redis-cli -p 9999 client list | awk '{print substr($12,6),$1,$12,$18}' | sort -nrk1,1 | cut -f1 -d " " --complement
# 5. 检查客户端输出缓冲区内存使用总量
redis-cli -p 9999 client list | awk 'BEGIN{sum=0}{sum+=substr($16,6)}END{print sum}'
# 6. 检查客户端输出缓冲区各客户端连接的内存使用排序
redis-cli -p 9999 client list | awk '{print substr($16,6),$1,$16,$18}' | sort -nrk1,1 | cut -f1 -d " " --complement | head -n10
# 7. 检查数据对象使用内存总量
redis-cli -p 9999 memory stats | grep -A 1 'dataset.bytes'

Summary

Most Redis memory issues can be located using the investigation steps described above.

A set of frequently used Redis memory‑diagnosis commands is provided to help operators quickly pinpoint the root cause.

A more extensive Redis memory‑checking script is also available for deeper analysis.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performancedatabaseredistroubleshootingMemoryOOM
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.