What are large key anti-patterns in Redis and how do you fix them?
Answer
A large key (also called "big key" or "hot key") is a key whose value is very large or whose collection contains too many members. Examples: a String value of 10MB, a Hash with 5 million fields, a Set with 1 million members, a List used as an unbounded queue. Problems: serializing/deserializing large values consumes significant CPU and memory on the client. Operations on large collections (like HGETALL on a million-field hash) block the single Redis thread for milliseconds, causing latency spikes for all other clients. To detect big keys: redis-cli --bigkeys scans the keyspace, or scan with SCAN + OBJECT ENCODING/MEMORY USAGE. Fixes: (1) Split large collections using key sharding (e.g., hash:bucket:{key % N}). (2) Use smaller page sizes and cursor-based iteration (HSCAN, SSCAN, ZSCAN). (3) Set a max size and use LTRIM to cap list growth. (4) Store large blobs in object storage (S3) and keep only the reference in Redis. (5) Compress values before storing.
Previous
What is Redis Stack and what does it add to vanilla Redis?
Next
What is CRDT support in Redis and how does it relate to Active-Active geo-distribution?
More Redis Questions
View all →- Advanced How does Redis Cluster sharding and the hash slot algorithm work in detail?
- Advanced What is consistent hashing and how does it compare to Redis Cluster's approach?
- Advanced What is memory optimization in Redis (ziplist, listpack, and encoding thresholds)?
- Advanced How does AOF rewrite work and how does it compare to RDB performance?
- Advanced What are Redis Functions (replacing Lua scripts in Redis 7+)?