How to install Redis on Debian

Post Reply
User avatar
webxtek
Posts: 51
Joined: Wed Nov 18, 2020 7:43 pm

Hi,

Short intro about Redis:

Redis, an acronym for Remote Dictionary Server, is a fast and open-source key-value data store that is stored in memory. The development of Redis began when its creator, Salvatore Sanfilippo, aimed to enhance the scalability of his Italian startup. Over time, Redis evolved into a versatile data store that is used as a database, cache, message broker, and queue.

With sub-millisecond response times, Redis can handle millions of requests per second, making it a valuable tool for real-time applications across industries such as gaming, advertising technology, financial services, healthcare, and the Internet of Things. Redis has become one of the most widely-used open-source engines and has been dubbed the "Most Loved" database by Stack Overflow for five consecutive years. Its lightning-fast performance makes Redis a popular choice for use in caching, session management, gaming leaderboards, real-time analytics, geospatial applications, ride-hailing services, chat/messaging platforms, media streaming, and pub/sub apps.

In the following steps, we will guide you through the installation process of Redis on a Debian server.

You must have shell access with sudo privileged account access to Debian 10 system. First of all, log in to your system and upgrade the current packages.


1st run:

Code: Select all

sudo apt update 

Code: Select all

sudo apt upgrade
2nd run

Code: Select all

sudo apt install redis-server
After installation, enable Redis service to start on system boot.

Code: Select all

sudo systemctl enable redis-server
Now navigate to your /etc/redis/redis.conf file and add this 2 lines on the end of the file:

Code: Select all

maxmemory 256mb
maxmemory-policy allkeys-lru
The above configuration tells Redis to remove any key using the LRU algorithm when the max memory of 256mb is reached. Save the configuration file and restart the Redis service:

Code: Select all

sudo systemctl restart redis-server
Install Redis PHP Extension (This is an optional step. If you need to connect Redis from PHP application, You need to install Redis PHP extension on your Debian system. To install Redis PHP extension, simply type:)

Code: Select all

sudo apt install php-redis
The installer will automatically enable redis extension for all the pre installed PHP versions. If you installer new PHP version after this, you can use below command to enable redis module. For example to enable extension for PHP 7.4, type:

Code: Select all

sudo phpenmod -v 7.4 -s ALL redis
Now Connect to Redis Server


Use redis-cli tool to verify the connection between the Redis server

Code: Select all

redis-cli

127.0.0.1:6379> ping
PONG
Few more examples of redis-cli command line tool:

Code: Select all

$ redis-cli info
$ redis-cli info stats
$ redis-cli info server
This tutorial helps you with the installation of Redis server on Debian 10 system.
Last edited by webxtek on Wed Dec 30, 2020 4:21 am, edited 1 time in total.
User avatar
isscbta
Team Member
Posts: 130
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 15 times
Been thanked: 3 times

The following is another way of installing Redis on Debian:

In your SSH, as root, run:

Code: Select all

apt-get update
apt-get install -y redis-server
apt-get install $(systemctl --full --type service --all | grep "php...-fpm" | sed 's#●##g' | awk '{print $1}' | cut -c1-6 | xargs -n 1 printf "%s-redis ")

sed -i "s|^supervised no|supervised systemd|g" /etc/redis/redis.conf
sed -i "s|^save |# save |g" /etc/redis/redis.conf
sed -i "s|^# maxmemory .*|maxmemory 1g|g" /etc/redis/redis.conf
sed -i "s|^# maxmemory-policy .*|maxmemory-policy allkeys-lru|g" /etc/redis/redis.conf

systemctl restart redis
redis-cli info memory
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

OR

New and quick way (for myVesta only) :

Code: Select all

v-update-myvesta
v-commander 'inst redis'
You can adjust 'maxmemory' by typing:

Code: Select all

sed -i "s|^maxmemory .*|maxmemory 4g|g" /etc/redis/redis.conf
systemctl restart redis
Post Reply