How to Install and Configure Redis 6.0 on Debian 11

Redis is a free, and open-source in-memory data structure store used as a message broker and database cache. You can use it with streaming solutions such as Apache Kafka to process, and analyze real-time data with sub-millisecond latency. Redis supports a lot of data structures including, Hashes, Strings, Hyperloglogs, Bitmaps, Geospatial indexes, sorted lists, and more. It is popular due to its wide language support, high availability, and automatic partitioning.

In this post, we will show you how to install and configure Redis 6 on Debian 11.

Prerequisites

  • A server running Debian 11.
  • A root password is configured on the server.

Install Redis 6 on Debian 11

The latest version of Redis is not included in the Debian 11 default repository. So you will need to install it from the Redis official repository.

First, install all the required dependencies using the following command:

apt-get install wget curl gnupg -y

Next, download and add the GPG key using the following command:

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

Next, add the Redis official repository using the following command:

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

Next, update the repository cache and install the Redis using the following command:

apt-get update -y
apt-get install redis-server -y

Once the Redis is installed, verify the Redis installation using the following command:

apt-cache policy redis-server

You should see the Redis package information in the following output:

redis-server:
  Installed: 6:6.2.6-3rl1~bullseye1
  Candidate: 6:6.2.6-3rl1~bullseye1
  Version table:
 *** 6:6.2.6-3rl1~bullseye1 500
        500 https://packages.redis.io/deb bullseye/main amd64 Packages
        100 /var/lib/dpkg/status
     6:6.0.16-3rl1~bullseye1 500
        500 https://packages.redis.io/deb bullseye/main amd64 Packages
     5:6.0.16-1+deb11u1 500
        500 http://security.debian.org/debian-security bullseye-security/updates/main amd64 Packages
     5:6.0.15-1 500
        500 http://debian.gtisc.gatech.edu/debian bullseye/main amd64 Packages

Manage Redis Service

You can manage the Redis service using the systemd.

To start the Redis service, run the following command:

systemctl start redis-server

To enable the Redis service to start at system reboot, run the following command:

systemctl enable redis-server

To check the status of the Redis service, run the following command:

systemctl status redis-server

You should see the following output:

? redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-11-28 07:15:00 UTC; 19s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 9079 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4679)
     Memory: 7.2M
        CPU: 82ms
     CGroup: /system.slice/redis-server.service
             ??9079 /usr/bin/redis-server 127.0.0.1:6379

Nov 28 07:15:00 debian11 systemd[1]: Starting Advanced key-value store...
Nov 28 07:15:00 debian11 systemd[1]: Started Advanced key-value store.

By default, Redis listens on port 6379. You can check it with the following command:

ss -antpl | grep redis

You will get the following output:

LISTEN 0      511        127.0.0.1:6379      0.0.0.0:*    users:(("redis-server",pid=9079,fd=6))
LISTEN 0      511            [::1]:6379         [::]:*    users:(("redis-server",pid=9079,fd=7))

Once you are finished, you can proceed to the next step.

Configure Redis

By default, Redis listens to the localhost. If you want to connect Redis from the remote host then you will need to allow Redis for the remote connection.

To do so, edit the Redis configuration file using your favorite editor:

nano /etc/redis/redis.conf

Comment out the following line:

#bind 127.0.0.1 -::1

Next, set the Redis password as shown below:

requirepass securepassword

Next, change the following line:

appendonly yes
appendfilename "appendonly.aof"

Save and close the file then restart the Redis service to apply the changes:

systemctl restart redis-server

Once you are finished, you can proceed to the next step.

Connect to Redis Instance

You can use the redis-cli command-line utility to connect the Redis server from the local or remote machine.

Run the following command to connect to the Redis instance:

redis-cli

Once you are connected, you will get the following shell:

127.0.0.1:6379>

Now, authenticate Redis using the password as shown below:

127.0.0.1:6379> auth securepassword

Next, check the server using the following command:

127.0.0.1:6379> INFO Server

You will get the following information:

# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:557672d61c1e18ba
redis_mode:standalone
os:Linux 5.10.0-8-amd64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:10.2.1
process_id:10828
process_supervised:systemd
run_id:b5ce185f0d4783dd3ddab8cabd38b0ee0263637b
tcp_port:6379
server_time_usec:1638085497530445
uptime_in_seconds:32
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:10695545
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0

Now, exit from the Redis instance using the following command:

127.0.0.1:6379> exit

It is recommended to benchmark the Redis to test its performance.

Run the following command to test the Redis with 10 parallel connections, for a total of 2k requests:

redis-benchmark -h 127.0.0.1 -p 6379 -n 2000 -c 10 -a securepassword

You will get the following output:

====== PING_INLINE ======                                         
  2000 requests completed in 0.05 seconds
  10 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.071 milliseconds (cumulative count 1)
50.000% <= 0.159 milliseconds (cumulative count 1090)
75.000% <= 0.207 milliseconds (cumulative count 1507)
87.500% <= 0.303 milliseconds (cumulative count 1769)
93.750% <= 0.359 milliseconds (cumulative count 1880)
96.875% <= 0.415 milliseconds (cumulative count 1942)
98.438% <= 0.455 milliseconds (cumulative count 1971)
99.219% <= 0.495 milliseconds (cumulative count 1985)
99.609% <= 0.791 milliseconds (cumulative count 1993)
99.805% <= 0.919 milliseconds (cumulative count 1997)
99.902% <= 1.031 milliseconds (cumulative count 1999)
99.951% <= 1.103 milliseconds (cumulative count 2000)
100.000% <= 1.103 milliseconds (cumulative count 2000)

Summary:
  throughput summary: 35714.29 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.239     0.096     0.231     0.343     0.439     0.727

For more command-line options, run the following command:

redis-benchmark --help

Conclusion

In the above post, we explained how to install and configure Redis 6 on Debian 11 server. You can now implement Redis in a production environment and use it as a message broker or for caching data in memory for faster retrieval. Feel free to ask me if you have any questions.

Share this page:

0 Comment(s)