How to setup Redis on Ubuntu Linux?


Redis (or Remote Dictionary Server) is an in-memory data structure store. It can be used as an in-memory key-value database, cache, or message broker and supports different kinds of abstract data structures such as strings, lists, maps, sets, bitmaps, streams, spatial indices, etc.

Originally it was written by Salvatore Sanfilippo and its initial version was released in 2009. Redis is known for its performance, flexibility, and multiple language support.

In this article, I will discuss how to install and configure Redis on a Ubuntu system.

Prerequisites

To follow this guide you should have a system running Ubuntu and access to a user account with sudo permissions.

How to install Redis in Ubuntu

Redis is available in the default repository of Ubuntu so you can install it directly by using the apt command on your system.

First, run the given command to update the apt package repository on your system –

sudo apt update

Next, use the given command to install Redis on a Ubuntu system –

sudo apt install redis-server

Press y and then enter when it asks for your confirmation.

You can verify the installation by using –

redis-server -v

This should display the output something as given in the image –

redis version

Check Redis server status

Once the installation is completed the Redis services will be started automatically. To check the status of the Redis server execute the given command in your terminal –

sudo systemctl status redis-server

If everything is set up correctly then you should see your Redis server is active and running as you can see in the image below –

redis server status

Configure Redis remote access

By default, you can connect to Redis only from the localhost, now what if you have the client connecting to the database on a remote system in this case you have to modify the Redis configuration file i.e. /etc/redis/redis.conf.

So open the configuration file by using a text editor –

sudo nano /etc/redis/redis.conf

In this file locate 127.0.0.0::1 and comment it by putting the # sign at the starting of the line.

redis.conf

Now restart the server to make all the changes effective –

sudo systemctl restart redis-server

To verify that everything has been set up correctly use the following command in your terminal –

redis-cli -h IP_ADDRESS_Redis_server ping

The server will display PONG in the output.

To know more about Redis and its usage you can visit its official website.

Conclusion

So I hope you have successfully set up Redis on your Ubuntu system. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.