How to Install and Configure Redis in Ubuntu 20.04

Install and Configure Redis on Ubuntu 20.04

Redis is a database caching service and an In-memory data structure storage. Meaning, 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. The following are supported maxmemory policy algorithms:-

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

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

volatiel_random : Remove random key with an expire set

allkeys_random : Keys are removed randomly without expire set

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

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

In this article, I’m going to install the latest version of Redis service on Ubuntu 20.04 and configure it.


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

Configuring Redis

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

Your file should look like,

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.

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 ‘Pokhara’> set office Pokhara

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


The article gives you the idea of installing and configuring the Redis server on Ubuntu 20.04. Hope you like the article.

Similar Posts