Install and Configure Redis in Ubuntu 20.04 - Step by step Process ?

Install and Configure Redis in Ubuntu 20.04 - Step by step Process ?

Redis, which stands for Remote Dictionary Server, is a fast, open-source, in-memory key-value data store for use as a database, cache, message broker, and queue.

This means that the frequent request to the database is cached by Redis and served from the fastest memory RAM.

It helps to reduce time delays and increase the performance of your application by accessing in microseconds. Data structures such as hashes, lists, sorted sets, strings, sets, are supported by Redis.

Normally, some GB of RAM is allocated to Redis. When running the applications, the memory is occupied. To refresh the storage at Redis maxmemory policy is used.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Redis queries.

In this context, we shall look into how to install the latest version of Redis service on Ubuntu 20.04 and configure it.

Supported maxmemory policy algorithms Includes:

1. volatile-lru : remove the (LRU) less recently used keys first which has an expire set

2. allkeys_lru : remove the less recently used keys first regardless of expire set

3. volatiel_random : Remove random key with an expire set

4. allkeys_random : Keys are removed randomly without expire set

5. volatile_ttl : Remove nearest expire time keys ie. having minor TTL value

6. noeviction : None of the keys are expired, just return write operation.

How to install Redis on Ubuntu Linux System ?

To install Redis on Ubuntu first make your system up to date:

$ sudo apt update

When an update is completed, install Redis using the apt package manager:

$ sudo apt install redis -y

After the installation is completed, check the version:

$ redis-cli -v

Now, start the Redis server by entering the following command:

$ sudo systemctl start redis-server

Enable the service so that it automatically starts when the server reboots:

$ sudo systemctl enable redis-server

Also, check the status of Redis server:

$ sudo systemctl status redis-server

The default port for Redis is 6379 and listens on IPv4 localhost as well as IPV6 loopback address. 

You can verify by executing the following command:

$ ss -ltn

How to configure Redis on Ubuntu ?

In the default installation of Redis, the configuration file is at /etc/redis/redis.conf.

To apply max memory limit and policy, first open the configuration file:

$ vi /etc/redis/redis.conf

You can add the following parameter in the file. For example, set memory limit to 2 GB. and noeviction maxmemory policy:

maxmemory 2gb
maxmemory-policy noeviction

Similarly, to add password add following in the same configuration file:

requirepass YourPassword

Save the file and restart the Redis service:

$ sudo systemctl restart redis-server

Note: You can also change default port and bind address from the configuration file.

Working with Redis CLI

Now, let's access Redis from its CLI. To login to Redis server just type:

$ redis-cli>

Now use password to login. ( if you have setup ):> auth YourPassword

Set name 'office' and value 'Linuxapt':> set office Linuxapt

Get the key from name:> get office

See all the keys in Redis:> keys *

See memory details:> info memory

Flush all the key:> flushall

login to different Redis server hosts and non-default port. 

For Example with default port 6380:

$ redis-cli -h -p 6380

[Need urgent assistance in fixing missing packages on Ubuntu Linux Systems? We are available to help you today. ]


This article covers the installing and configuring the Redis server on Ubuntu 20.04. #Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. You can use it as a Memcached alternative to store simple key-value pairs. 

To Install and Configure Redis on Ubuntu:

In order to get the latest version of Redis, we will use apt to install it from the official Ubuntu repositories.

1. Update your local apt package cache and install Redis by typing:

$ sudo apt update
$ sudo apt install redis-server

This will download and install Redis and its dependencies. 

2. Following this, there is one important configuration change to make in the Redis configuration file, which was generated automatically during the installation.

Open this file with your preferred text editor:

$ sudo nano /etc/redis/redis.conf

Inside the file, find the supervised directive. This directive allows you to declare an init system to manage Redis as a service, providing you with more control over its operation. The supervised directive is set to no by default. Since you are running Ubuntu, which uses the systemd init system, change this to systemd.

3. Start by checking that the Redis service is running:

$ sudo systemctl status redis

4. If, however, you prefer to start up Redis manually every time your server boots, you can configure this with the following command:

$ sudo systemctl disable redis

5. To test that Redis is functioning correctly, connect to the server using the command-line client:

$ redis-cli

6. To restart Redis:

$ sudo systemctl restart redis.service

Search by typing a one letter Word Term Here