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
Your port will be open at localhost:5000. You want to go to the url
http://localhost:5000/repos/arunkrish11
(it is actually http://localhost:5000/repos/github_id), so you can see how many repos someone has. You can see something like this,
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>`);
}
If you refresh the page, then you can see the fetching time is high for each time we refresh.

(First fetching after code removal)

(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 fetching after the return of code)

(Second fetching after the return of code)
So that's it. Catch you in another post. Til then take care, bye.

Top comments (1)
Have any thoughts on this?