What is Redis? | Redis crash course

What is Redis? | Redis crash course

What problem does it solve?

To understand what problem Redis solves, let's take the example below.

Let's think, you have an application with a user, that requests some data from the server.

The server then goes to the database and runs 5 query commands to extract that data, and then the server returns the data to the user. Now, when the user gets back the response, immediately he hits the refresh button, for the same data a new request is made to the server and the server again goes to the database to run those 5 queries.

So you see there is a problem. We are fetching the same data again and again.

What if there is static data, let's say a simple number, and we are querying again and again to fetch the same data from the database?

This is ok if your application is small, but what if your application has over a million users? The cost of your database and server would skyrocket.

This is where services like REDIS come into the picture.

What is Redis?

Redis is an in-memory data store, that stores the computed data on the server's ram.

Note: We store the data on the server's RAM, we don't use secondary memory, since the read and write speed of RAM is much much faster than that of secondary memory.

Now the request tree looks somewhat like this:

First, when the user requests the server, the server then checks the Redis if that data is present or not, if the data is present, it responds to the user, otherwise it goes to the database, grabs that data comes back to the server stores the value on redis and also gives back the response to the user.

So you see, we save a lot of database queries.

Installing Redis

To install Redis, let's head over to Install Redis. You will see there are different options.

You can these options, but I will suggest going with the docker installation. To install Redis on docker, run the following command:

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

After running this command and installing Redis, you can simply run the container from CLI or go the the docker desktop and you from there also.

Datatypes

You can head over to Redis datatypes to learn more about the datatypes supported by Redis.

Did you find this article valuable?

Support Manas Upadhyay by becoming a sponsor. Any amount is appreciated!