Advertisement
Advanced Redis, Data Types

What are the internal memory encoding optimizations Redis applies to small collections, and how do they affect performance and memory usage?

Short answer

Redis automatically uses more compact internal encodings, such as a listpack, for small hashes, lists, sets, and sorted sets that stay below certain configurable size thresholds, which significantly reduces memory usage compared to the standard encoding, though operations can…

Save Redis mock interview
Advertisement
AModel answer
Redis automatically uses more compact internal encodings, such as a listpack, for small hashes, lists, sets, and sorted sets that stay below certain configurable size thresholds, which significantly reduces memory usage compared to the standard encoding, though operations can become slightly slower once a collection grows past that threshold and converts to its regular, more memory intensive encoding.
Example

-- Check the internal encoding currently used for a key OBJECT ENCODING myhash CONFIG GET hash-max-listpack-entries

Real-world example
A team storing many small hashes for user preferences notices significant memory savings by ensuring their hashes stay below the configured listpack entry threshold, taking advantage of Redis's automatic compact encoding.
Likely follow-ups
  • How do you adjust the size thresholds that control when Redis switches encodings?
  • What happens to performance when a collection crosses this encoding threshold?
Related topics