What is OBJECT ENCODING in Redis?
Answer
OBJECT ENCODING key returns the internal memory encoding Redis is using for a key's value. Redis automatically selects the most memory-efficient encoding based on the value's size and content. For example, a Hash with fewer than 128 fields and values under 64 bytes uses listpack (formerly ziplist), a very compact contiguous memory format. Once it grows beyond those thresholds, it is converted to hashtable, which is faster but uses more memory. Strings use int encoding for integers, embstr for short strings (≤44 bytes), and raw for longer strings. Understanding encodings is important for memory optimization — keeping your data structures below the threshold limits (tunable with hash-max-listpack-entries, etc.) keeps them compact and cache-friendly.
More Redis Questions
View all →- Intermediate What is Redis Cluster and how does it shard data?
- Intermediate What is the difference between Redis Sentinel and Redis Cluster?
- Intermediate How do MULTI and EXEC work in Redis transactions?
- Intermediate What is WATCH and optimistic locking in Redis?
- Intermediate What is Lua scripting in Redis and when should you use it?