almessadi.
Back to Index

Redis Gets More Interesting Once You Stop Using It Like a Cache_

HyperLogLog, sorted sets, and other Redis data structures are useful because they encode specific trade-offs, not because they are obscure.

PublishedJuly 8, 2024
Reading Time5 min read

Redis is easy to reduce to "fast key-value cache."

That misses the part that makes it valuable: Redis exposes specialized data structures with very specific performance and memory trade-offs.

HyperLogLog Is the Best Example

If you need an approximate count of unique values, a set may be overkill.

A Redis set gives you exact uniqueness, but the memory cost grows with the number of members.

HyperLogLog trades exactness for tiny fixed memory usage:

PFADD stream:123:views 203.0.113.10
PFADD stream:123:views 203.0.113.11
PFCOUNT stream:123:views

That makes it a good fit for:

  • approximate unique visitors
  • approximate unique events
  • trend measurement where small error is acceptable

It is the wrong fit when exact counts are required for billing, compliance, or money movement.

That is why a small proof of concept matters before adoption. Feed HyperLogLog with realistic traffic and compare the approximate result against an exact set on a sample dataset. The memory win is often excellent, but the acceptable error rate should be verified against the actual product use case, not assumed from a blog post.

That is the pattern with Redis data structures generally: each one encodes a useful trade.

Think in Problem Shapes

Redis becomes more powerful when you ask:

  • do I need exactness or approximation?
  • do I need ordering?
  • do I need uniqueness?
  • do I need time-window behavior?

That leads naturally to sorted sets, bitmaps, HyperLogLog, streams, and the rest of the toolbox.

Further Reading