Introduction to
Redis Cache

As your website attracts more visitors, the amount of data that needs to be stored increases. While expanding your database storage allows you to store more data, it also results in longer response times as more requests are sent to the database. An alternative solution to this problem is caching.

Development
July 2, 2020
Martijn van der Put

One of the popular caching servers is Redis. Redis offers significant advantages such as:

  • High speed
  • Support for multiple programming languages
  • Scalability
  • Databases

What is Caching?

Caching is the process of storing data in a temporary storage component, which can then be easily retrieved to serve the data faster.


Caching works on the simple principle of efficiently reusing previously computed data stored on top of the actual storage layer. Data in the cache is typically stored in RAM and can be utilized in conjunction with a software component.

How does Caching improve customer experience?

Let's look at an example: Suppose you visit your favorite online store and complete an order. Assume the application needs to fetch your profile data ten times for various steps (retrieving shipping address, previous cart items, saved payment details, etc.). Each time the server accesses the database and responds to the application, it takes 2 seconds. Therefore, the total time you wait for the application to load is 2 * 10 = 20 seconds.

Assuming this application has a cache server, it takes the full 2 seconds to retrieve the information from the database the first time. However, after that, the information is stored in the cache. Retrieving details from the cache is extremely fast, taking half the time of the initial request (1 second). Thus, your total wait time during your shopping journey is 2 + 1*10 = 12 seconds. This is almost half the time you would have spent waiting in the first scenario, meaning your experience in the second scenario is much better due to the reduced wait time. More importantly, it helps your application significantly improve its SEO ranking, as page load time plays a crucial role in determining it.


What is Redis?

Redis is an open-source NoSQL database effectively used as a cache server following the key-value store principle. Only those with the key can access the data. Redis stands for Remote Dictionary Server. It supports various data structures such as hashes, strings, lists, and bitmaps.

Redis typically operates in a Master/Slave configuration and also supports sharding, making it fairly straightforward to distribute the dataset across multiple instances of Redis. Another key feature of Redis is that it primarily operates atomically: you can safely set or increment a key, add or remove elements from a set, or even increment a counter.


How to install Redis on Ubuntu?

Before you begin installing Redis on Ubuntu, ensure you are logged in with sudo privileges.

Step 1: Update the list of apt packages by running the following command in your SSH terminal:

sudo apt update

Step 2: Install Redis with the following command:

sudo apt install redis-server

Step 3: Redis will automatically start after installation. You can check the status of the service with the following command:

sudo systemctl status redis

If everything is set up correctly, you will not receive an error message when running this command. This indicates that your Redis server is ready for use.


Conclusion

Caching is a popular mechanism for delivering web page content quickly to visitors. Redis is one of the databases for caching needs that can be used worldwide.

Cookies
This site uses anonymous cookies. Click on "Agree" if you agree to the use of cookies, or click on "Change" to determine your preferences.
This site uses anonymous cookies.
Agree Change Decline