🔴 Redis Intermediate

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.