Redis is an open-source (BSD licensed), in-memory key-value data structure store used as a database, cache, and message broker. Redis supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlog logs, geospatial indexes, and streams. Redis also provides high availability with its Redis Sentinel software logic, and this creates automatic partitioning across multiple Redis nodes with Redis Cluster.
At the end of the guide, you will know how to install and configure Redis on your Debian 10 Buster operating system.
Table of Contents
- Recommended OS: Debian 10 Buster
- User account: A user account with sudo or root access.
Before you begin, make sure your Debian 10 system is up to date:
sudo apt update && sudo apt upgrade -y
Installing Redis on Debian 10
By default, Redis 5 series comes included in the Debian 10 repositories. To install Redis on your Debian 10 Buster operating system, type the following command:
sudo apt install redis-server -y
[email protected]:/home/joshua# apt-get install redis-server -y Reading package lists… Done Building dependency tree Reading state information… Done The following additional packages will be installed: libhiredis0.14 libjemalloc2 liblua5.1-0 lua-cjson redis-tools Suggested packages: ruby-redis The following NEW packages will be installed: libhiredis0.14 libjemalloc2 liblua5.1-0 lua-cjson redis-server redis-tools 0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded. Need to get 989 kB of archives.
Once installed, start Reddis and enabled it by default on boot:
sudo systemctl start redis-server && systemctl enable redis-server
[email protected]:/home/joshua# sudo systemctl start redis-server && systemctl enable redis-server Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable redis-server
Next, verify the status and make sure Redis is running and, more importantly, with no errors:
sudo systemctl status redis-server
Note, Reddis actively listens to localhost on port 6379. To confirm this type, the following:
ps -ef | grep redis
[email protected]:/home/joshua# ps -ef | grep redis redis 4095 1 0 12:46 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379 root 4454 2161 0 12:54 pts/0 00:00:00 grep redis
Now, while you are testing everything is working and operational, it’s a good idea to connect to your Redis service and then perform a ping test. To do this, enter the following command:
Once connected, your terminal will display (127.0.0.1:6379). Now ping the Redis service as follows:
[email protected]:/home/joshua# redis-cli 127.0.0.1:6379> ping PONG
Type the following to exit the Redis instance:
Congratulations, you have installed Redis on your Debian 10 Buster operating system and verified it is operational. Next, you can configure Redis.
Configure Redis on Debian 10
Configure Redis as a Cache
Redis can be configured in a few ways. The most notable action of why people use Redis is for caching purposes. To do this, you need to open the “/etc/redis/redis.conf” file using nano editor.
sudo nano /etc/redis/redis.conf
Now, add the following to the end of the file. Note that you can change the memory value to whatever you like or, more importantly, optimal for your web application and server hardware.
maxmemory 500mb maxmemory-policy allkeys-lru
As you can see, the setting in the guide has 500MB dedicated to Redis as it is on a dedicated host with lots of RAM to spare. Once the 500MB is exhausted, Redis removes any key as per the LRU algorithm.
Another option is if you like your Redis service to listen to all services, you can do this in two ways:
Comments the bind to IP:
# bind 127.0.0.1 ::1
Note, make sure your internal network is trustworthy and appropriate security controls are in place.
Once done, save your changes “CTRL+O” then exit “CTRL+X). Now restart the Redis service by typing:
sudo systemctl restart redis-server
Allow Redis UFW Rules
You will need to create UFW allow rules on the TCP port 6379. Depending on your installation and requirements if using singular or in a cluster network, some examples below:
Additional network IP server instance:
sudo ufw allow proto tcp from <ip address> to any port 6379
Cluster network with many instances:
sudo ufw allow proto tcp from <ip address>/24 to any port 6379
Note, the second UFW rule is a subnet rule. Note, make sure the internal network is secure and trustworthy before allowing it.
Now, as you tested at the start of the guide by pinging your Redis service to make sure it was operational, you can test the firewall rules and changes in IP by using the “redis-cli” command:
redis-cli -h <ip address> ping
If setup correctly, the output should be:
Comments and Conclusion:
In the guide, you have learnt how to install Redis on Debian 10 Buster by using its default repositories through the apt package manager. You have learnt how to test the service by pinging it and changing the memory limit and network interface to suit various setups.
Overall, Redis is an outstanding cache, the debate will always be between do I choose Memcached or Redis, both are extremely powerful and have both pros and cons, normally the rule of thumb Redis is better for smaller stuff, and Memcached is better for larger as its multicore however most will not notice any difference.
If you would like an alternative to Redis, check out our Debian 10 Buster Memcached install guide.
To find more information about how to manage your Redis installation, visit the Redis documentation page.