Redis Server Installation and Configuration

Introduction
This guide will walk you through the installation and configuration of Redis Server on Ubuntu 22.04.
What is Redis Server?
Redis Server is an open-source, in-memory data structure store, used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries, and streams.
Prerequisites
- A server running Ubuntu 22.04
- A non-root user with sudo privileges
Installation
Before starting, it is recommended to update your system packages to the latest version. You can update them with the following command:
sudo apt update
Once your system is up-to-date, you can proceed to install Redis Server.
Step 1 - Install Redis Server
You can install Redis Server with the following command:
sudo apt install redis-server
Step 2 - Enable Remote Access
Next, you will need to configure Redis Server to listen on all interfaces. You can do this by editing the /etc/redis/redis.conf
file:
sudo nano /etc/redis/redis.conf
Find the following line:
bind 127.0.0.1
And replace it with the following line:
bind 0.0.0.0
You should only allow remote access to Redis Server from trusted networks. Otherwise, you may expose your Redis Server to the public internet. If you are unsure, you should leave this setting as is.
Save and close the file when you are finished.
Step 3 - Securing Redis Server
By default, Redis Server is not secured. You can secure it by editing the /etc/redis/redis.conf
file:
sudo nano /etc/redis/redis.conf
Find the following line:
# requirepass foobared
And replace it with the following line:
requirepass <password>
Note: Replace <password>
with your own password.
Step 4 - Connect to Redis Server
You can connect to Redis Server using the redis-cli
command:
redis-cli
You should see the following output:
127.0.0.1:6379>
You can now run Redis commands. For example, simple GET and SET commands:
127.0.0.1:6379> SET mykey "Hello World"
OK
127.0.0.1:6379> GET mykey
"Hello World"
Step 5 - Enable Redis Server
Finally, you will need to enable Redis Server. You can do this by editing the /etc/redis/redis.conf
file:
nano /etc/redis/redis.conf
Find the following line:
supervised no
And replace it with the following line:
supervised systemd
Redis will use systemd to manage the Redis Server process as a supervisor. Systemd will automatically start Redis Server when the system boots up.
By default, Redis Server is not enabled. You can enable it with the following command:
sudo systemctl enable redis-server
You can check the status of Redis Server with the following command:
sudo systemctl status redis-server
You should see the following output:
...
Active: active (running) since ...
...
Conclusion
Congratulations! You have successfully installed and configured Redis Server on Ubuntu 22.04. You can now start using Redis Server to store and retrieve data.