Redis is an open-source in-memory data store that can be used as a database, cache, or message broker. It is known for its high performance and scalability, and is widely used in a variety of applications. In this tutorial, we will show you how to install and configure Redis 6.0 on Debian 11.
Prerequisites
Before getting started, make sure you have a clean installation of Debian 11 and that you are logged in as a user with sudo privileges. You will also need to have the apt
package manager installed on your system.
To check if apt
is installed, you can use the following command:
apt --version
If apt
is not installed, you can install it by running the following command:
sudo apt install apt
Once apt
is installed, you are ready to proceed with installing Redis.
Step 1: Add the Redis package repository
To install Redis 6.0 on Debian 11, we will add the Redis package repository to our system and install the Redis package from the repository.
To add the Redis package repository, open a terminal and run the following commands:
sudo apt install wget
wget <http://download.redis.io/redis-stable.tar.gz>
tar xvzf redis-stable.tar.gz
cd redis-stable
These commands will download the Redis source code, extract it, and change the current directory to the Redis source directory.
Next, run the following command to compile and install Redis:
sudo make install
This will compile the Redis source code and install the Redis binaries on your system.
Step 2: Configure Redis
Once Redis is installed, we can configure it to suit our needs. To do this, we will edit the Redis configuration file, which is located at /etc/redis/redis.conf
.
To edit the Redis configuration file, run the following command:
sudo nano /etc/redis/redis.conf
This will open the configuration file in the nano
text editor.
Scroll down to the Security
section of the configuration file and find the protected-mode
setting. By default, this setting is set to yes
, which means that Redis is running in protected mode. In protected mode, Redis will only accept connections from clients that are connected to the same host as the Redis server.
To allow Redis to accept connections from remote hosts, set the protected-mode
setting to no
:
protected-mode no
Save the changes to the configuration file by pressing CTRL+O
, and then exit the editor by pressing CTRL+X
.
Step 3: Start and enable the Redis service
Now that Redis is installed and configured, we can start the Redis service and enable it to start automatically on boot.
To start the Redis service, run the following command:
sudo systemctl start redis
To enable the Redis service to start automatically on boot, run the following command:
sudo systemctl enable redis
Step 4: Test the Redis installation
To test the Redis installation, we can use the redis-cli
command-line tool to connect to the Redis server and run some basic commands.
To start the redis-cli
tool, run the following command:
redis-cli
This will open the redis-cli
prompt, which you can use to run Redis commands.
To test the connection to the Redis server, run the PING
command:
PING
If the connection to the Redis server is successful, the redis-cli
tool will return PONG
.
To set a key-value pair in the Redis database, run the SET
command, followed by the key and value:
SET testkey testvalue
To retrieve the value of a key from the Redis database, run the GET
command, followed by the key:
GET testkey
If the key exists in the database, the redis-cli
tool will return the value of the key.
To exit the redis-cli
prompt, run the QUIT
command:
QUIT
Conclusion
In this tutorial, you learned how to install and configure Redis 6.0 on Debian 11. You learned how to add the Redis package repository, install the Redis package, configure the Redis service, start and enable the Redis service, and test the Redis installation using the redis-cli
tool. With Redis installed and configured, you can start using it as a database, cache, or message broker in your applications.