1. What is Redis hot key?
Hot key (Hot Key) definition:
The key that is frequently accessed (read/write) within a unit time will lead to concentrated access and excessive pressure.
Hot key Common manifestations:
- Extremely high QPS (a key is accessed tens of thousands of times per second)
- A business reads and writes a key at high frequency (such as flash sale inventory, ranking top1)
- Redis instance CPU exception,But only serve one key
Risks of hot keys:
question | illustrate |
---|---|
Excessive pressure on a single point | All requests are called to the same key |
Cache breakdown | Hot key expires, a large number of requests fall to the DB |
Master-slave replication delay | Hot key changes frequently → Master-slave synchronous data increases sharply |
Node imbalance (cluster) | The key distribution in Redis Cluster is uneven |
Hot key solution:
question | illustrate |
---|---|
Excessive pressure on a single point | All requests are called to the same key |
Cache breakdown | Hot key expires, a large number of requests fall to the DB |
Master-slave replication delay | Hot key changes frequently → Master-slave synchronous data increases sharply |
Node imbalance (cluster) | The key distribution in Redis Cluster is uneven |
2. What is Redis big key?
Big key (Big Key) definition:
Refers tovalue too big(For example, a Hash contains millions of fields, or a List has more than 100,000 items) or a ** string with a large size (such as a few MB images)** key.
Risks of big keys:
question | illustrate |
---|---|
❗ Delete blocking |
DEL Large key blocks Redis single thread |
❗ Master-slave copying slows down / lost | The master node transmits a large key → replication delay |
❗ Causes RDB/AOF to surge | Dump will be stuck once |
❗ Affects the performance of a single command | The operation of a large key will slow down, for exampleHGETALL
|
Big key recognition method:
use
redis-cli --bigkeys
Command scan instanceuse
redis-rdb-tools
Analyze RDB filesView via slow query log + monitoring
HGETALL
、LRANGE
、SMEMBERS
The big key
Big key solution:
plan | illustrate |
---|---|
✅ Split data structure | For example, a large hash is split into multiple small hashs (click ID) |
✅ Control the maximum number of fields/elements | Controlling individual structure members ≤ 10K |
✅ Disable Dangerous Commands | For example, closeKEYS , FLUSHALL , HGETALL
|
✅ Delayed/slow delete strategy | For example, large keys are divided into batchesUNLINK delete |
✅ Limit maximum value size | Do not exceed a few KB of strings, avoid exceeding MTU |
The difference between UNLINK vs DEL:
Order | illustrate |
---|---|
DEL |
Delete immediately (blocking thread) |
UNLINK |
Asynchronous deletion,Non-blocking ✅ |
✅ Redis 4.0+ It is recommended to use UNLINK to delete large keys!
Summary comparison table
type | Trigger method | risk | Solution core |
---|---|---|---|
Hot key | Access the same key at high frequency | CPU soaring, breakdown, hot spots | Local cache, sharding, current limiting, preheating |
Big key | value structure too large | Slow query, blocking, synchronization issues | Segment splitting, asynchronous deletion, structural constraints, UNLINK |
This is all about this article about Redis hot key and big key issues. For more related Redis hot key and big key content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!