Published on

Redis Is Underrated

Authors

I recently stumbled on this video:

It was a light-bulb moment. I've always viewed Redis as a caching tool that only high-scale companies use to shave milliseconds off of requests.

When I first looked into Redis, one of the first things I learned is that Redis deletes data when it's shutdown and that data loss is expected. Turns out... that was extremely misleading and I've been ignoring Redis for no good reason!

From Dreams of Code's video above, I'm convinced that Redis could be used as a primary database. It's fast, it's simple, and it's powerful.

Redis Stack

Shortly after, I found another video that goes into more detail about "RedisJSON". RedisJSON is provided by Redis Stack, which also provides: "Search and Query, Time Series, and Probabilistic". This is when I started to really get excited about Redis. It seems like a perfectly good alternative for NoSQL databases if you can store JSON. With the added benefits from Redis Stack, it seems like a no-brainer to use Redis.

To name a few more features that Redis surprised me with:

Having just finished a project that used PostgreSQL as the primary database, all of the drawbacks are fresh in my mind. Having to manage migrations, writing schemas, and the overall complexity is too much for practically all of my projects.

PostgreSQL definitely has its place, don't get me wrong, but I think Redis will be my go-to for prototyping in the foreseeable future. It's a simple one-liner to stand up a new instance, one line to connect, and one line for most of my queries. The fact that it can do pub/sub and all these other things is just icing on the cake.

How's it Going?

I've been using Redis for a few weeks now and it's... going great! I've been using RedisJSON almost exclusively. I haven't had a reason to use any of the other data types or features like pub/sub yet.

I've built two smaller projects that utilize Redis as the primary database. One is a trading bot, the other is a Discord bot. The code is much simpler than it would be if I were using PostgreSQL. I haven't regretted it yet.

There are some open questions that I have for the future:

  • How well will Redis scale with a large amount of data?
  • If I wanted to migrate from Redis to MongoDB, how difficult would that be?
    • There does not appear to be a straightforward way to do this. Unfortunate.

For now, I'll leave you with a one-liner to stand up a Redis Stack instance:

$ docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

Open localhost:8001 in your browser and you should see the web UI.