Whenever we think of high performance in serving responses to clients, we think of caching. Caching means storing data temporarily in a store, so that it can be accessed directly from that store instead of performing heavy read/write operations on the database. For example, Person A has requested a list of books published in the year 1986. The list will be fetched from the database and served to person A.
In addition, a copy of the result will be stored in the cache. If Person B has made the same request, instead of going all the way to the database, the result is fetched from the caching store and served to Person B. In this way, seek-time delays are avoided and results are fetched in microseconds.
Redis is one such caching store. It stands for REmote DIctionary Server. Although other caching stores do exist (Memcached being an example), Redis has an edge because of the wide variety of data structures it supports.
Installing Redis for development:
Download and install Redis through the command line using the following commands:
- Install Redis using brew
brew install redis
- To start Redis
brew services start redis
- Download binaries
$ sudo tar xzf redis-6.2.0.tar.gz
$ cd redis-6.2.0
- Run Redis with
To check if the Redis installation is successful, you can open a terminal and check with the following command:
The server should respond with a PONG:
For a beginner, you can interact with redis-cli with the following set of basic commands:
- In a new terminal, open redis cli by typing the following command
- Set key-value pair as follows:
set company Payoda
- Retrieve value as follows:
Areas where Redis has the edge:
Session Management and Caching:
Details such as User Id, user name, last accessed page, most recent request, etc, can be stored in Redis. This can be used to manage user sessions at an application level.
As mentioned in the introduction, frequently accessed data can be cached using Redis.
The data can be easily stored and retrieved with simple lines of code by using the inbuilt data structures provided by Redis.
Unlike some caching mechanisms that support only key/value pairs, Redis supports a wide range of data structures which are listed as follows:
- Sorted sets
Redis allows replication of data across multiple replica servers. Even if the primary server experiences an outage, it can be recovered at a fast pace.
Redis shines when it comes to applications that involve machine learning, real-time analytics, rich media streaming, chats, leaderboards, etc.
In addition to all of the above, Redis offers a vast scope of other benefits, making it a popular choice for a wide range of applications across multiple industries and use cases.
Payoda is at the forefront of digital disruption and our expertise in transformative technologies leads the way. Get in touch with us to empower your digital journey.
Author: Shiny Metilda Christina Joseph