Quick revision
The short answer
OBJECT ENCODING reports int, embstr or raw for strings; listpack or hashtable for hashes; intset, listpack or hashtable for sets; listpack or skiplist for sorted sets; and listpack or quicklist for lists. Redis uses the compact encoding while a value stays under small limits such as 128 entries and 64-byte elements, and converts to the general structure as soon as one limit is exceeded. It matters because a compact value can use several times less memory, at the cost of linear scans, and the conversion does not reverse while the key lives.
What to remember
In this answer, we saw that each Redis type has compact encodings for small values and general structures for large ones: int, embstr and raw for strings, listpack or hashtable for hashes, intset, listpack or hashtable for sets, listpack or skiplist for sorted sets, and listpack or quicklist for lists. The limits are small because listpack is scanned linearly, and a value that converts stays converted until the key is rebuilt, which is why a small change to data can change memory use a lot.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
OBJECT ENCODING reports int, embstr or raw for strings; listpack or hashtable for hashes; intset, listpack or hashtable for sets; listpack or skiplist for sorted sets; and listpack or quicklist for lists. Redis uses the compact encoding while a value stays under small limits such as 128 entries and 64-byte elements, and converts to the general structure as soon as one limit is exceeded. It matters because a compact value can use several times less memory, at the cost of linear scans, and the conversion does not reverse while the key lives.
Why this question is asked
Two hashes with the same fields can use very different amounts of memory in Redis, and the reason is invisible unless we know about encodings. Interviewers ask this because it explains surprises we meet in production, such as memory tripling after a small schema change, and because it shows whether we understand the trade between memory and CPU that Redis makes on every key. In this answer, we will recap what an encoding is, go through each data type and its limits, look at listpack and why the limits are small, and see why a converted key stays converted.
1A Quick Recap: Type Versus Encoding
Every Redis value has a type, which is what we see from the outside: string, hash, set, sorted set or list. The type decides which commands work. Each value also has an encoding, which is how Redis lays the value out in memory. The same type can have two or three encodings, and Redis picks one automatically.
The command OBJECT ENCODING key tells us which one a key has. The general rule is simple: small values get a compact encoding, a single block of bytes with almost no pointers, and large values get a general-purpose structure such as a hash table, which is fast for any size but costs much more memory per element.
2Strings: int, embstr and raw
A string that holds an integer, such as a counter, is stored as int: the number lives directly in the object, with no separate buffer. A string of up to 44 bytes is stored as embstr, which puts the object header and the characters in one memory allocation. Anything longer is raw, with the header and the characters in two separate allocations. The 44-byte limit comes from fitting the header and the string into a 64-byte allocator size class.
3Hashes, Sets, Sorted Sets and Lists
A small hash is stored as a listpack, one byte array holding field, value, field, value in order. It stays a listpack while it has at most hash-max-listpack-entries fields (128 by default) and every field and value is at most hash-max-listpack-value bytes (64 by default). Break either limit and it becomes a hashtable. Sorted sets work the same way with zset-max-listpack-entries and zset-max-listpack-value (also 128 and 64), and become a skiplist plus a hashtable, the skiplist for ordered ranges and the hashtable for looking up a member's score.
Sets have one more option. A set of only integers is an intset, a sorted array of integers, up to set-max-intset-entries (512). From Redis 7.2, a small set with non-integer members uses a listpack (set-max-listpack-entries 128, set-max-listpack-value 64), and larger sets become a hashtable.
Lists are a quicklist: a linked list whose nodes are listpacks, each limited by list-max-listpack-size. The default of -2 means each node holds up to 8 KB. From Redis 7.2, a small list is a single plain listpack, and OBJECT ENCODING reports listpack until it outgrows one node.
| Type | Compact encoding | Limit (default) | General encoding |
|---|---|---|---|
| string | int / embstr | integer / up to 44 bytes | raw |
| hash | listpack | 128 fields, 64-byte values | hashtable |
| set | intset / listpack (7.2+) | 512 integers / 128 x 64 bytes | hashtable |
| sorted set | listpack | 128 members, 64-byte members | skiplist + hashtable |
| list | listpack (7.2+) | fits one node | quicklist of 8 KB listpacks |
4Why the Compact Limits Are Small
Listpack replaced the older ziplist in Redis 7.0. The old configuration names, such as hash-max-ziplist-entries, still work as aliases. Both are plain byte arrays: each entry stores its length and data, so finding a field means scanning from the start. That is O(N), but for 100 entries in a few hundred bytes it is faster than chasing pointers, because the whole value sits in one or two CPU cache lines.
The saving is large. A hashtable stores each field and value as separate allocations with a dictionary entry and bucket slot, tens of bytes of overhead per field. A listpack stores a small integer field in two or three bytes. But as the listpack grows, every HGET scans further and every insert may reallocate the whole array, so the limits are kept small to keep that linear cost bounded.
5Conversion Only Goes One Way
When a hash exceeds a limit, Redis converts it to a hashtable on the spot. If we later delete the long field, or remove fields until only ten remain, the hash stays a hashtable. Redis does not check on every delete whether the value could shrink back. The same holds for sets and sorted sets. Lists are the exception in 7.2 and later, where a quicklist that shrinks well below the limit can become a single listpack again.
The memory only returns when the key is rebuilt, for example by reading it, deleting it and writing it again, by DUMP and RESTORE, or when the whole dataset is reloaded from an RDB file at restart or on a new replica, because loading creates each value fresh with the best encoding for its current size.
6Follow-up questions
How would you measure the memory of a single key?
MEMORY USAGE key returns the bytes the key and its value use, including the object overhead. For aggregate values it samples some elements (5 by default) and extrapolates, so for large keys we pass SAMPLES 0 to count every element, at the cost of a slower call. Comparing MEMORY USAGE of two similar keys with different encodings shows the difference directly.
Can we change the encoding limits at runtime?
Yes, with CONFIG SET, for example hash-max-listpack-entries. The new limits apply to values as they are created or converted; existing keys keep their current encoding until they are rebuilt.
Why does a sorted set need both a skiplist and a hashtable?
The skiplist keeps members ordered by score, which makes ZRANGE and ZRANK O(log N). The hashtable maps each member to its score, which makes ZSCORE O(1) and lets ZADD find an existing member quickly. Each covers what the other is slow at.
7Conclusion
In this answer, we saw that each Redis type has compact encodings for small values and general structures for large ones: int, embstr and raw for strings, listpack or hashtable for hashes, intset, listpack or hashtable for sets, listpack or skiplist for sorted sets, and listpack or quicklist for lists. The limits are small because listpack is scanned linearly, and a value that converts stays converted until the key is rebuilt, which is why a small change to data can change memory use a lot.
Open with
OBJECT ENCODING shows how a value is laid out. Strings are int for integers, embstr up to 44 bytes, where the header and characters share one allocation, and raw beyond that.
Then, if they want more
Hashes and sorted sets are listpack while small, by default up to 128 entries and 64-byte elements via hash-max-listpack-entries and -value and the zset equivalents, and become a hashtable, or a skiplist plus hashtable for sorted sets, as soon as either limit is passed.
Sets are an intset for up to 512 integers, a listpack for small non-integer sets from 7.2, then a hashtable. Lists are a quicklist of listpack nodes, 8 KB each with the default of -2, and from 7.2 a small list is just one listpack. Listpack replaced ziplist in 7.0; the old config names still work.
These compact forms are single byte arrays scanned in O(N), so they save a lot of memory but cost CPU, which is why the limits are small. And conversion is one-way: a hash that became a hashtable stays one after fields are removed, until the key is rebuilt by DUMP and RESTORE, a rewrite or a reload.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Redis 7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What does OBJECT ENCODING report for strings, hashes, sets, sorted sets and lists, when...": https://scrivio-interview-library.netlify.app/databases/redis-internals/beef488567/