What internal memory encoding does Redis use for small sets and sorted sets, and how does this affect performance and memory usage as they grow?
Short answer
Redis stores small sets containing only integers using a highly compact intset encoding, and small sets or sorted sets in general using a compact listpack encoding, automatically switching to a full hash table or skip list based structure once they exceed configurable size…
Advertisement
AModel answer
Redis stores small sets containing only integers using a highly compact intset encoding, and small sets or sorted sets in general using a compact listpack encoding, automatically switching to a full hash table or skip list based structure once they exceed configurable size thresholds, trading memory efficiency for improved performance on larger collections.
Example
OBJECT ENCODING myset CONFIG GET set-max-intset-entries CONFIG GET zset-max-listpack-entries
Real-world example
A team storing many small sets of numeric identifiers benefits significantly from Redis's compact intset encoding, achieving meaningful memory savings across their large number of small collections compared to a less specialized encoding.
Likely follow-ups
- What are the specific size thresholds that trigger a switch to the larger encoding?
- Does this encoding choice affect the actual commands available for interacting with the set?
Related topics