How do you use shorter key names and more compact data structures to meaningfully reduce Redis's overall memory footprint?
Short answer
Since Redis stores the key name itself alongside every value, using shorter, more concise key naming conventions can add up to meaningful savings across millions of keys, and choosing compact data structures like hashes for small objects, taking advantage of Redis's efficient…
Advertisement
AModel answer
Since Redis stores the key name itself alongside every value, using shorter, more concise key naming conventions can add up to meaningful savings across millions of keys, and choosing compact data structures like hashes for small objects, taking advantage of Redis's efficient internal encodings, can further reduce memory usage compared to less efficient alternatives like storing everything as separate strings.
Example
-- Longer key name uses more memory per key SET user_profile_data_for_customer_12345 'value' -- Shorter, still clear key name SET u:12345 'value'
Real-world example
A large scale application with millions of keys shortens their key naming convention and switches small objects to hashes, achieving a noticeable reduction in overall memory usage across their entire dataset.
Likely follow-ups
- How much memory savings can typically be achieved just by shortening key names?
- Does shortening key names make the codebase harder to understand?
Related topics