DEV Community

Cover image for Okay, What is Redis?
Arun Krish
Arun Krish

Posted on

Okay, What is Redis?

What is Redis?
Redis (Remote Dictionary Server) is an open-source, in-memory, NoSQL data structure store used primarily as a database, cache, and message broker. It stores data in RAM for extremely fast read/write speeds, commonly for caching, session management, and real-time analytics, handling data as key-value pairs.

In simple words, it will act like a cache memory to store data as key - value pair. I watched a tutorial to understand Redis. He showed something like, if we don't use redis the website take too much time for each fetching. But if we use redis the first fetching only take that much time, second fetch onward the fetching time will be low.

In order to understand that, you need to do this tutorial. The code is given below as github gist. Download or copy the code and dance with me.
Redis Gist Code

You want to open your terminal with current directory and run the two codes given below. One for installing the packages and second one for starting the port.

npm i
npm start
Enter fullscreen mode Exit fullscreen mode

Your port will be open at localhost:5000. You want to go to the url

http://localhost:5000/repos/arunkrish11
Enter fullscreen mode Exit fullscreen mode

(it is actually http://localhost:5000/repos/github_id), so you can see how many repos someone has. You can see something like this,

http://localhost:5000/repos/arunkrish11

Now you want to inspect the site and go to the network section. There will be something named finish time. It actually shows how time took to load the site, yeah the fetching time. Now you want to go to the code and remove the first section,

// 1. Check cache
    const cached = await client.get(username);
    if (cached) {
      return res.send(`<h2>${username} has ${cached} repos (cached)</h2>`);
    }
Enter fullscreen mode Exit fullscreen mode

If you refresh the page, then you can see the fetching time is high for each time we refresh.

First refresh
(First fetching after code removal)

Second refresh
(Second fetching after code removal)

Now we want to paste the code that we removed earlier.If you refresh now, you can see the difference. The first fetching only take that much time, second onward the fetching time is low.

First refresh
(First fetching after the return of code)

Second refresh
(Second fetching after the return of code)

So that's it. Catch you in another post. Til then take care, bye.

Checkout my profiles.
GitHub
DevTo

Top comments (1)

Collapse
 
arunkrish11 profile image
Arun Krish

Have any thoughts on this?