Redis Changes Every few Years - Are you up to date?
Redis has grown to be much more than just a cache
The Blind Spot
It’s common to use a technology for one purpose and nothing else. Postgres is thought of as an SQL DB, but you can also use it as an event store, message queue, outbox or document db.
Redis is a key/value store, but you can also use it as a PubSub notifiers, a search DB, an event store or a host of distributed data structures.
This is not a documentation issue. This habit is very human. You want a message queue, you may default to the thing you know. If you’ve used RabbitMQ before, you may want to prefer that over other objective choices.
Whenever your team is assessing technologies they are including their current experience with it into the equation. Very pragmatic. But also rigid.
We can tackle Postgres some other time, let’s look into Redis today.
If you’re like me, you learned about Redis in your first few years of being an engineer. So if you haven’t checked the Redis docs since then, there’s quite a few nifty features you may be missing out on!
PubSub
You can find the related commands here.
Every software has a favourite or mascot Message Queue or PubSub notifier. While these are not the same thing (generally) - they are often satisfied using similar technology.
Redis PubSub is a popular choice for enterprise cases where technologies are used that don’t have natural SDKs for all services that need it. Here’s a code example to highlight the basics:
An exercise to the reader:
What delivery-related problems do you see with this approach?
What’s the immediate benefit?
What can go wrong?
Native Streams
The Streams aren’t obvious at first. Due to their unconventional naming, they are hiding behind the XADD, XRANGE family of commands. I also only learned about this capability after 10 years of using Redis.
These commands were introduced in 2018 with Redis 5.0. It’s a popular choice nowadays for lightweight intra-server communication. Especially in tech stacks like PHP and python because they don’t lend themselves naturally to running a gRPC server (well).
This video from the official Redis Academy highlights their usage:
Popular Data Structures
Probabilistic data structures, event sourcing and vector search are one of the top commands used in use cases for caching, circuit breaking and operational middleware.
Redis 4.5 and 5.0 introduced new data structures to be used in most available Redis setups with the introduction of Redis Stack.
HyperLogLog for to count unique values on a large scale
Bloom Filters to efficiently capture “is it missing?” questions on a massive scale
Documents (native JSON) to manipulate deep properties inside an object
Search for text lookups when you don’t need a giant durable store
How are you using it?
Let me know in the comments or reply to this email!
My use case is a bit different! As a case study to learn Rust and to help other developers level up.