Redis is a free, open-source, cross-platform NoSQL, and in-memory Key-value data structure store, used as a database server, cache, and message broker. It is written in C and developed by Salvatore Sanfilippo. It provides replication features that help you to set up highly available clusters in your production environments.

In this tutorial, I will explain how to install the Redis server on Debian 11.

Prerequisites

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

Install Redis Server

By default, the Redis package is included in the Debian 11 default repository. You can install it easily using the following command:

apt-get install redis-server -y

Once the Redis server is installed, you can check the status of Redis using the following command:

systemctl status redis-server

You should get the following output:

? 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-09-26 02:40:45 UTC; 3s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 379829 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 9510)
     Memory: 6.9M
        CPU: 62ms
     CGroup: /system.slice/redis-server.service
             ??379829 /usr/bin/redis-server 127.0.0.1:6379

Sep 26 02:40:45 debian11 systemd[1]: Starting Advanced key-value store...
Sep 26 02:40:45 debian11 systemd[1]: Started Advanced key-value store.

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

ss -antpl | grep redis

You should get the following output:

LISTEN 0      511        127.0.0.1:6379       0.0.0.0:*    users:(("redis-server",pid=379829,fd=6))                                                                                                      
LISTEN 0      1024       127.0.0.1:9121       0.0.0.0:*    users:(("redis_exporter",pid=14922,fd=3))                                                                                                     
LISTEN 0      511            [::1]:6379          [::]:*    users:(("redis-server",pid=379829,fd=7))                                                                                                      

Next, let’s connect to your Redis service and then perform a ping test.

To perform the test, enter the following command:

redis-cli

Once you are connected, you should get the following output:

127.0.0.1:6379>

Now ping the Redis service as follows:

127.0.0.1:6379> ping

You should get the following output:

PONG

Configure Redis

Generally, Redis is used for caching purposes. You can configure it by editing the file /etc/redis/redis.conf:

nano /etc/redis/redis.conf

First, comment on the following line to allow remote connection:

#bind 127.0.0.1 ::1

Next, define the memory by adding the following lines at the end of the file:

maxmemory 500mb 
maxmemory-policy allkeys-lru

Save and close the file when you are finished then restart the Redis service to apply the changes:

systemctl restart redis-server

Now, verify the Redis listening port using the following command:

ss -antpl | grep redis

You should get the following output:

LISTEN 0      511          0.0.0.0:6379       0.0.0.0:*    users:(("redis-server",pid=380643,fd=7))                                                                                                      
LISTEN 0      1024       127.0.0.1:9121       0.0.0.0:*    users:(("redis_exporter",pid=14922,fd=3))                                                                                                     
LISTEN 0      511             [::]:6379          [::]:*    users:(("redis-server",pid=380643,fd=6))       

Verify Redis Remote Connection

If the UFW firewall is installed in your server then you will need to allow Redis port 6379 for the remote server from where you want to connect Redis. You can allow it using the following command:

ufw allow proto tcp from remote-server-ip to any port 6379

Next, connect to the Redis server from the remote machine using the following command:

redis-cli -h redis-server-ip ping

If everything is fine, you should get the following output:

PONG

Conclusion

In the above guide, we explained how to install the Redis server on Debian 11. We also explained how to configure Redis to allow remote connection. I hope you can now integrate Redis with your application for caching purposes.

<img alt="Hitesh Jethva" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/hitesh-80.jpg6160149b3b3de.jpg" ezimgfmt="rs rscb5 src ng ngcb5" src="data:image/svg xml,”>

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.