Redis is a database management system that stores data in a key-value format, where each unique key in the database corresponds to a specific value.
To help you integrate Redis into your projects, we have prepared installation guides for three operating systems: Windows, Ubuntu, and CentOS.
After installation, we will configure Redis to make it ready for use.
You will need WSL2 (Windows Subsystem for Linux) to install Redis on Windows. Refer to the WSL2 installation guide on the Microsoft website.
Once the installation and setup of WSL is complete, you will have a Linux system (by default, Ubuntu) running on your machine via WSL.
Now you can proceed to the Installing Redis on Ubuntu chapter and follow the instructions.
We will install Redis on Ubuntu using the official repository. This guide is also applicable for Debian installations.
Before installing Redis, update the package lists to ensure you get the latest available version:
sudo apt update
Now, install Redis using the following command:
sudo apt install redis-server -y
Start the Redis service and enable it to start automatically on system boot:
sudo systemctl start redis
sudo systemctl enable redis
To check if Redis is running correctly, use:
sudo systemctl status redis
If Redis is active, the output will confirm that the service is running.
Now, let's install Redis on CentOS 9.
Run the following command:
sudo dnf install redis
Start the Redis service:
sudo systemctl start redis
Enable Redis to start automatically on system boot:
sudo systemctl enable redis
Redis setup is done by modifying the configuration files. These files remain the same across all versions. In this guide, we will set up Redis on Ubuntu and connect to it remotely.
To set up basic configuration, we need to modify two key parameters:
Here are the steps to achieve that.
Step 1: Generate a secure password:
openssl rand 25 | openssl base64 -A
Example output:
/37DQhAt5MBq/34Lj24Ppn5LI/UZksAZJQ==
Since attackers can attempt up to 150,000 passwords per second, it is crucial to choose a strong password. Copy the generated password and proceed to the configuration file.
Step 2: Open the configuration file:
sudo nano /etc/redis/redis.conf
Modify configuration settings. Find the line:
bind 127.0.0.1 ::1
Comment it out by adding #
at the beginning:
# bind 127.0.0.1 ::1
Find the line:
protected-mode yes
Change it to:
protected-mode no
In the Security
section, locate the commented-out line:
# requirepass foobared
Add the following line below it, replacing the value with your generated password:
requirepass /37DQhAt5MBq/34Lj24Ppn5LI/UZksAZJQ==
Save and close the file.
Step 3: Restart Redis to apply changes:
sudo systemctl restart redis.service
Step 4: Verify Redis listening interfaces. Check which network interfaces Redis is listening to:
sudo netstat -lnp | grep redis
Step 5: Connect remotely to your Redis instance. On your local machine, open Terminal or Command Prompt and use redis-cli to connect:
redis-cli -h 192.168.43.37 -p 6379 -a /37DQhAt5MBq/34Lj24Ppn5LI/UZksAZJQ==
Step 7: Test the connection by running the ping command:
192.168.43.37:6379> ping
# Output:
PONG
Set and retrieve a key-value pair:
192.168.43.37:6379> set key test
# Output:
OK
192.168.43.37:6379> get key
# Output:
"test"
A Database as a Service (DBaaS) is a cloud-hosted database solution. Using Redis as a DBaaS provides several advantages:
With Hostman, you can set up a cloud Redis database in just a few minutes.