How to install Redis in Amazon Linux 2

You are currently viewing How to install Redis in Amazon Linux 2

Redis is an in-memory data structure store that is used as a database, cache, and message broker. It is widely used for its speed and versatility and is supported by many programming languages. In this article, we will discuss how to install Redis on Amazon Linux 2, a popular distribution of Linux.

Before we start with the installation process, it is important to update the system’s package information. To do this, run the following command in your terminal:

sudo yum update -y

Now that your system is up-to-date, we can proceed with the installation of Redis. Run the following command to install Redis on Amazon Linux 2:

sudo amazon-linux-extras redis6
sudo yum install redis -y

Once the installation is complete, we can start the Redis service. Run the following command to start the Redis service:

sudo systemctl start redis


It is recommended to enable the Redis service to start at boot. This way, Redis will start automatically whenever the system restarts. To enable the Redis service, run the following command:

sudo systemctl enable redis


To verify the Redis installation, we can check its status by running the following command:

sudo systemctl status redis


If Redis is installed and running correctly, the response should be similar to the following:

Redis.service - Redis In-Memory Data Store
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-02-01 12:34:56 UTC; 3 weeks ago
Main PID: 12345 (redis-server)
CGroup: /system.slice/redis.service
└─12345 /usr/bin/redis-server 127.0.0.1:6379
Finally, you can test the Redis installation by running the Redis command line interface. To do this, run the following command:
redis-cli ping

The response should be PONG, indicating that Redis is installed and running correctly.

After installing Redis on Amazon Linux 2, you can test the installation by writing and reading sample data from the Redis database. To do this, you can use the Redis command line interface (CLI).

To write sample data to Redis, run the following commands in the Redis CLI:

redis-cli
SET key value

The SET command sets the value of a key in the Redis database. In this example, we set the value of the key to value. The response OK indicates that the data was written successfully.

To read the sample data from Redis, run the following command in the Redis CLI:

GET key
"value"

The GET command retrieves the value of a key in the Redis database. In this example, we retrieve the value of the key, which should be the value.

You can also use Redis data structures like hashes, lists, sets, and sorted sets to store and retrieve more complex data structures. The Redis documentation provides a comprehensive list of commands that you can use to interact with the Redis database.

In conclusion, installing Redis on Amazon Linux 2 is a straightforward process. By following the steps outlined in this article, you can have Redis up and running in no time. Redis is a versatile and fast data store that can be used for many purposes, and its support for multiple programming languages makes it a popular choice among developers.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply