Redis is Not What You Think It Is.


Redis is Not What You Think It Is.

This issue is brought to you by:

Securing Vibe Coding: Addressing the Security Challenges of AI-Generated Code

As AI coding tools become embedded in daily development,
they bring a new wave of productivity, and new security risks.
On November 20 @ 11AM EST, Snyk Staff Developer Advocate Sonya Moisset
will break down the security implications of vibe coding and share actionable strategies to secure AI-generated code at scale. Attendees can earn 1 CPE credit by registering with your ISC2 member ID and attending this session live!

It's not just a cache.
For years, we've put Redis in a tiny box labeled "fast, in-memory cache".
But I spent over 100 hours watching it in production, and what I saw changed my mind completely.
It’s a beast, and most of us are only using 10% of it.


The Great Database Divide

Here’s a problem we all face: we need our applications to be both fast and reliable.
We need to retrieve data instantly, but we also can't afford to lose it if the server crashes.
It’s a constant war between speed and safety.

Fast vs. Safe: The Old Way

The classic solution is to use two different tools for the job:
We grab Redis for its lightning speed and use it for short-lived information.
This is the Redis we all know.
You set a key with an expiration time:

SET mykey "some temporary data" EX 3

and poof, it's gone when you need it to be - in this instance, 3 seconds later.
Then, for the "important" stuff, we use a traditional database, like a sqlite or postgresql.
The thinking is simple: cache equals fast, database equals safe.
But Redis, can do both!!

Redis: Your Fast AND Safe Database

So, how do I solve it differently.
When I can, I use Redis for both.

Redis is way more than a simple k/v store.
It has built-in data structures like hashes, which are perfect for storing entire objects, just like a document in a nosql database.
You can store a user with their ID, email, name, and login count, all under a single key with

HSET user:1 name "Eve" email "eve@example.com" login_count 1

But what about safety you ask?
What happens if the server restarts?
By default, Redis does occasional snapshots, which aren't reliable enough for critical data.
But there's a feature that changes everything: the Append Only File, or AOF.

By turning on AOF with

CONFIG SET appendonly yes

you tell Redis to log every single write operation to a file.
Every. Single. One.
If the server crashes, Redis simply replays this log to restore its state perfectly.
Suddenly, your in-memory cache is a durable, persistent database.

You can even create your own indexes -
Let’s say you need to find a user by their email.
You can create a key that maps the email address directly to the user's ID, giving you a super-fast lookup with

SET user:email:eve@example.com 1

And what about handling things like unique usernames.
Redis has Sets, which are unordered buckets of unique data.
You can add a username to a set with

SADD usernames "eve"

and Redis will automatically reject any duplicates.

Finally, for the ultimate database feature, what about race conditions?
You can use a transaction:
You tell Redis to watch a key with

WATCH user:1

Then you start a transaction with

MULTI

and queue up your commands, like

HINCRBY user:1 login_count 1

If another client changes that key before you run

EXEC

the entire transaction is aborted.
No more corrupted data.

You get the speed of in-memory with the reliability of a traditional database.
All in one tool you're probably already using.

And this, is how you achieve in memory speed, with DB persistence achieving the fastest database you can think of.

Yes, it comes with a price, but this debate is for another week :)

Thank you for reading.

Feel free to reply directly with any question or feedback.

Have a great weekend!

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

I’m Done With Manual Proxies. (Use Traefik Instead) This issue is brought to you by: Incident.io: Move fast when you break things The all-in-one AI platform for on-call, incident response, and status pages—built for fast-moving teams. Get started for FREE! If you’ve ever felt like pulling your hair out while manually editing Nginx config files just to add one simple container, this is for you. Modern infrastructure is dynamic, but our proxies are often static. In the old days, you’d spin up a...

I replaced Docker with THIS. This issue is brought to you by: Graphite: The next generation of code review. Graphite is the AI code review platform where teams ship higher code, faster. Get started for FREE! You know why you’re here. Because reproducible environments make you tick but too much friction? makes you.. sick 🥁. After 12 years of containerizing / virtualenv-ing, I’ve finally found something that ticks all the boxes. I’m talking about throwing out npm, rvm, nix-env, virtualenv and...

Wait... NGINX can do WHAT?! This issue is brought to you by: Reliable DNS hosting & domain name managementWith DNSimple! From a streamlined interface to single-click integrations, DNSimple delivers the tools you need to simplify your day. Developers and system admins love our single-click integrations and automation tools for domains, DNS, and more. Enterprise teams simplify management of the most complex domain environments through our NEW Domain Control Plane. Try FREE for 30 days! Most...