Okay, What is Redis?
Source: Dev.to
What is Redis?
In simple words, Redis acts like a cache memory to store data as key‑value pairs. Without Redis, a website can take a long time to fetch data on each request. With Redis, the first fetch takes the normal amount of time, but subsequent fetches are much faster because the data is served from the cache.
Demo Tutorial
The following tutorial demonstrates the performance difference with and without Redis caching.
Setup
- Clone or copy the code from the GitHub Gist (link not included here).
- Open a terminal in the project’s root directory and run the commands below.
npm i
npm startThe application will be available at http://localhost:5000.
Visit:
http://localhost:5000/repos/Replace “ with any GitHub username (e.g., arunkrish11) to see how many public repositories that user has.
Observing Fetch Times
- Open the browser’s developer tools and go to the Network tab.
- Look for the entry named finish time – this shows how long the request took to load.
Without Cache
Comment out (or remove) the cache‑checking block in the source code:
// 1. Check cache
const cached = await client.get(username);
if (cached) {
return res.send(`
## ${username} has ${cached} repos (cached)
`);
}Refresh the page repeatedly. You will notice that the fetch time remains high on each refresh because the request is hitting the GitHub API every time.
With Cache
Restore the cache‑checking block (the code you removed earlier). Now refresh the page:
- First fetch – takes the normal amount of time as the data is retrieved from GitHub and stored in Redis.
- Subsequent fetches – are much faster because the data is served from the Redis cache.
This demonstrates how Redis can dramatically improve response times for repeated requests.
End of tutorial.