2024 02 07

What is Redis?

In my last post, I mentioned that I would be attempting Code Crafters’s Redis course, which challenges us to write our own, simple version of the popular open-source data structure store. It’s important to know what we’re building first before we start, so I want to go over, at a high level, what Redis is and what it’s used for.

As for that second part, Redis is a pretty generic tool that can support many different use cases. I see it most often used as an application cache, but you can use it as a message broker, as your persistent, shared datastore available over a network, or any number of other incarnations to support your application’s operation. Redis can run locally alongside your application, or you can access the data you’re storing within it over private networks or the cloud.

Redis stands for Remote Dictionary Server, and works similarly to dictionaries (or maps, hash tables, or whatever your language of choice prefers to call them), except that it allows you to read from and write to that data across application spaces, or even over the network (hence remote). Just like a dictionary type, you can ask the redis server to store some value and associate it with a key, but unlike a dictionary type, you can perform sophisticated queries against your data. The most primitive type of data that Redis can store is a string, but more complex structures like lists, sets, bitmaps, or even JSON are all possible. You interact with your Redis datastore via an extensive list of commands.

For more information about what Redis is and what it can do, check out the official website for Redis (not to be confused with Redis Enterprise, which is a paid service offered by the makers of Redis).

First Look

The first thing I notice is that the course does not start with an upfront account of the features that you’ll be expected to implement, which is a bummer. I would prefer to know what the expected direction is when starting on a project like this, because that’s how you would approach a project you were building on your own.

It looks like you can answer these questions by looking ahead at the upcoming stages of the project, though, so let’s do that now:

The first thing we’ll do is implement a simple TCP server and bind to a specific port. Once this is up and running, we want to start implementing specific redis commands, so they’ll have us start by implementing the PING command, and then expanding this to respond to multiple PINGs sent on the same connection.

After this, we’ll augment our Redis clone to handle multiple concurrent clients either by implementing separate threads or by creating an event loop. Then, we’ll implement some more commands, starting with ECHO, and followed by GET and SET. Finally, we’ll want to add the ability for a key to automatically expire.

Code Crafters delivers additional optional content for their projects in the form of extensions, and the Redis project currently includes a single extension which expects your Redis implementation to handle persistent storage. That sounds like a valuable learning opportunity, but let’s get the rest of the features written first. Let’s start with that TCP server.


Thanks for reading,

Alec