How to install and configure Redis 6 on Debian 11

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 Debian 11.

Prerequisites

To follow along, ensure that you have:

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

Table of Content

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

1. Update the Debian Server

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

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

The redis server packages is available in the default debian repos but for version 5. Install it using this command

<meta charset="utf-8">sudo apt-get install redis-server

Confirm the installed version using this command:

$ apt-cache policy redis-server
redis-server:
  Installed: 5:6.0.16-1+deb11u1
  Candidate: 5:6.0.16-1+deb11u1
  Version table:
 *** 5:6.0.16-1+deb11u1 500
        500 http://security.debian.org/debian-security bullseye-security/main amd64 Packages
        100 /var/lib/dpkg/status
     5:6.0.16-1~bpo11+1 100
        100 http://cdn-aws.deb.debian.org/debian bullseye-backports/main amd64 Packages
     5:6.0.15-1 500
        500 http://cdn-aws.deb.debian.org/debian bullseye/main amd64 Packages

You can install the latest stable version (version 6) of Redis from the official packages.redis.io APT repository. Add the repository to the apt index, update it and install:

Install gnugpg

sudo apt install -y gnupg

Add apt key

curl https://packages.redis.io/gpg | sudo apt-key add -

Add Redis repo

echo "deb https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

Now update the repolist and install redis

sudo apt-get update
sudo apt-get install redis-server

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 Sun 2021-11-21 10:05:16 UTC; 4min 50s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 3057 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4626)
     Memory: 7.2M
        CPU: 425ms
     CGroup: /system.slice/redis-server.service
             └─3057 /usr/bin/redis-server 127.0.0.1:6379

Nov 21 10:05:16 ip-10-2-40-167 systemd[1]: Starting Advanced key-value store...
Nov 21 10:05:16 ip-10-2-40-167 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 0.0.0.0 using this line:

bind * -::*

To set password in redis, use this:

requirepass j2GfJuLFR8

To add a pid file to redis:

pidfile /var/run/redis/redis-server.pid

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:

127.0.0.1:6379> auth j2GfJuLFR8
OK
127.0.0.1:6379>

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

Check redis information.

127.0.0.1:6379> INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.

127.0.0.1:6379> INFO Server
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:557672d61c1e18ba
redis_mode:standalone
os:Linux 5.11.0-1019-aws x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:9.3.0
process_id:251198
process_supervised:systemd
run_id:9a4f90740c3f6a327b521f928e7e6f9405a1fc51
tcp_port:6379
server_time_usec:1637319052373797
uptime_in_seconds:28
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:9929100
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0

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 127.0.0.1 -p 6379 -n 10000 -c 15 -a j2GfJuLFR8
====== PING_INLINE ======
  10000 requests completed in 0.23 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.031 milliseconds (cumulative count 1)
50.000% <= 0.095 milliseconds (cumulative count 6342)
75.000% <= 0.103 milliseconds (cumulative count 7740)

..........

Cumulative distribution of latencies:
29.540% <= 0.103 milliseconds (cumulative count 2954)
99.810% <= 0.207 milliseconds (cumulative count 9981)
99.990% <= 0.303 milliseconds (cumulative count 9999)
100.000% <= 0.407 milliseconds (cumulative count 10000)

Summary:
  throughput summary: 91743.12 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.121     0.032     0.127     0.167     0.183     0.319

For more options and examples, use:

$ redis-benchmark --help

Conclusion

In this guide, we have managed to install and configure Redis server on a Debian server.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy