How to install and configure Redis 6 on Ubuntu 22.04 

Pinterest LinkedIn Tumblr

Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.

In this tutorial we are going to learn how to install Redis 6 on Ubuntu 20.04.

Related Content


To follow along, ensure that you have:

  • An updated Ubuntu 22.04 server
  • Access to the Internet
  • Root access to the server or user with sudo access

Table of Content

  1. Update Ubuntu Server
  2. Installing Redis
  3. Configuring Redis
  4. Connecting and performing basic operations in Redis
  5. Performing Redis Benchmark

1. Update the Ubuntu Server

Before proceeding, ensure that the server is updated using this command (as a root user):

sudo apt update
sudo apt -y upgrade 

Let us also ensure vim is installed using this command since we will use it later:

sudo apt install -y vim

2. Installing redis

You can install recent stable versions of Redis from the official APT repository. Add the repository to the apt index, update it and install:

curl | sudo apt-key add -
echo "deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt update
sudo apt install redis

Use this command to confirm the redis package installed:

$ apt-cache policy redis-server
  Installed: 6:7.0.0-1rl1~jammy1
  Candidate: 6:7.0.0-1rl1~jammy1
  Version table:
 *** 6:7.0.0-1rl1~jammy1 500
        500 jammy/main amd64 Packages
        100 /var/lib/dpkg/status
     6:6.2.7-1rl1~jammy1 500
        500 jammy/main amd64 Packages
     5:6.0.16-1ubuntu1 500
        500 jammy/universe amd64 Packages

Now that the service has been installed, let’s start it with this command:

sudo systemctl start redis-server

Enable the service so it starts on boot:

sudo systemctl enable redis-server

After the service starts, use this command to check the status of the service:

$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-05-27 13:42:54 UTC; 13s ago
   Main PID: 1483 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4394)
     Memory: 5.8M
        CPU: 103ms
     CGroup: /system.slice/redis-server.service
             └─1483 "/usr/bin/redis-server" "" "" "" "" "" "" ""

May 27 13:42:54 systemd[1]: Starting Advanced key-value store...
May 27 13:42:54 systemd[1]: Started Advanced key-value store.

The above indicates that the service has been started successfully.

3. Configuring Redis

The redis configuration file is located in this path /etc/redis/redis.conf. In this section, we are going to update the redis configuration file to allow remote access, to set an authentication password, to add a pid file and to Set Persistent Store for Recovery.

Edit redis config file using this:

vim /etc/redis/redis.conf

To allow remote access to the redis instance, bind redis to using this line:

bind * -::*

To set password in redis, use this:

requirepass j2GfJuLFR8

To add a pid file to redis:

pidfile /var/run/redis/

Set Persistent Store for Recovery by changing the appendonlyvalue to yes

appendonly yes
appendfilename "appendonly.aof"

Restart redis service to apply changes:

sudo systemctl restart redis-server

4. Connecting and performing basic operations in Redis

Connecting to redis locally:

# redis-cli

To authenticate:> auth j2GfJuLFR8

You should receive OK in the output. If you input a wrong password, Authentication should fail.

Check redis information.> INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.> INFO
# Server
os:Linux 5.15.0-1005-gcp x86_64
monotonic_clock:POSIX clock_gettime

5. Performing Redis Benchmarking

Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.

# redis-benchmark -h -p 6379 -n 10000 -c 15 -a Vi9PQD2FCDtkLF
====== PING_INLINE ======
  10000 requests completed in 0.34 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

Latency by percentile distribution:
0.000% <= 0.063 milliseconds (cumulative count 1)
50.000% <= 0.247 milliseconds (cumulative count 5027)
75.000% <= 0.359 milliseconds (cumulative count 7523)
87.500% <= 0.455 milliseconds (cumulative count 8751)
93.750% <= 0.527 milliseconds (cumulative count 9431)
96.875% <= 0.567 milliseconds (cumulative count 9728)
98.438% <= 0.599 milliseconds (cumulative count 9845)
99.219% <= 0.647 milliseconds (cumulative count 9927)


  throughput summary: 38759.69 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.237     0.072     0.231     0.351     0.559     1.743

r[email protected]:~#

For more options and examples, use:

$ redis-benchmark --help


In this guide, we have managed to install and configure Redis 6 on an Ubuntu server 22.04.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment