Building an Acquaintance with Redis

Payoda Technology Inc
3 min readMar 12, 2021

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:

In Mac:

  • Install Redis using brew

brew install redis

  • To start Redis

brew services start redis

In Linux:

  • Download binaries

$ sudo wget https://download.redis.io/releases/redis-6.2.0.tar.gz

$ sudo tar xzf redis-6.2.0.tar.gz

$ cd redis-6.2.0

$ make

  • Run Redis with

$ src/redis-server

Redis-cli

To check if the Redis installation is successful, you can open a terminal and check with the following command:

redis-cli ping

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

redis-cli

  • Set key-value pair as follows:

set company Payoda

  • Retrieve value as follows:

get company

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.

Data structures:

Unlike some caching mechanisms that support only key/value pairs, Redis supports a wide range of data structures which are listed as follows:

  • Strings
  • Sets
  • Sorted sets
  • Lists
  • Hashes
  • Bitmaps
  • HyperLogLogs

Persistence:

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

--

--

Payoda Technology Inc

Your Digital Transformation partner. We are here to share knowledge on varied technologies, updates; and to stay in touch with the tech-space.