Redis is an in-memory data structure like a store that can be utilized as a cache, streaming engine, or database. Instead of using the complex query language, Redis helps the developers to program their code with simple statements to store the data. The Redis supports many data structures, like strings, hashes, sets, and so on. Moreover, it also provides the features of Replication and the Redis cluster that provides automatic partitioning.
Keeping in view the importance of the Redis, this guide demonstrates the working and usage of the Redis on Ubuntu 22.04. The content of this post is as follows:
Let’s start with the first one:
Method 1: Installation of Redis Using the Default Repository of Ubuntu 22.04
Ubuntu comes with a lot of packages that are included in the default repository. Redis is also one of them. For installing Redis on Ubuntu 22.04, the following steps are carried out:
Step 1: Update System’s Packages
The best practice before getting any package from the default repository is to update the system first:
$ sudo apt update
Step 2: Install Redis
To install the latest Redis-server from Ubuntu’s repository, use the below-mentioned command as follows:
$ sudo apt install redis-server -y
To confirm the installation, check the status of the “Redis” server via the following command:
$ sudo systemctl status redis-server
The above active status of the Redis server confirms that Redis has been successfully installed on Ubuntu.
Method 2: Installation of Redis Using the PPA Repository on Ubuntu 22.04
Another method to install Redis on Ubuntu is using the PPA repository. In this method, we will first add the PPA repository of Redis using the command:
$ sudo add-apt-repository ppa:redislabs/redis
After adding the PPA repository, update the Ubuntu packages/repositories:
$ sudo apt update
Finally, use the APT package manager to install the Redis on Ubuntu 22.04:
$ sudo apt install redis -y
To confirm the installation, we will check the version of Redis using the command:
$ redis-server -v
How to Configure Redis on Ubuntu 22.04?
To use the Redis server, you need to configure it to use it on Ubuntu. This section provides the necessary configuration steps to configure Redis on Ubuntu 22.04:
Step 1: Enable the Redis Service Now
The first and foremost step to dealing with any server is to enable its services so that the service is enabled irrespective of the reboot:
$ sudo systemctl enable --now redis-server
Step 2: Allow Redis to Listen on Every Network Interface
Redis do not accept any remote connections, it only responds to the requests of a local host or the machine on which it is being used. It is necessary to connect the database to the same machine as well. Suppose you want to allow the other remote connections to connect with Redis. In that case, you have to configure “Redis” so that it listens to addresses other than Localhost:
To do so, we will open the configuration file of Redis with the help of the nano editor using the command:
$ sudo nano /etc/redis/redis.conf
In the file, find the line that begins with the “bind” and replace it with the line shown in the figure:
Step 3: Set the Redis Password
In the same file “/etc/redis/redis.conf”, look for the “requirepass” line and write your password in front of it:
Restart the “Redis” server to apply the changes:
$ sudo systemctl restart redis-server
Step 3: Verify the Changes
Verify the above changes by checking that Redis is listening on port “6379”:
$ ss -an | grep 6379
After this, allow all the TCP traffic on port “6379”:
$ sudo ufw allow 6379/tcp
Step 4: Access the Redis CLI
Now, when all the configurations are done, open the “Redis CLI” with the command:
$ redis-cli
Authorize your identity using the “AUTH” keyword with the password you have set (step 3) in the configuration file:
> AUTH <password>
Ping to check the working of the Redis:
> ping
To quit the Redis-CLI, use the command:
> quit
How to Uninstall the Redis on Ubuntu 22.04?
To uninstall the Redis from Ubuntu, we can use the apt package manager with its autoremove option:
$ sudo apt remove --autoremove redis-server -y
That’s it from this guide! You have learned the installation and configuration of the Redis server on Ubuntu 22.04.
Conclusion
For installing the Redis server on Ubuntu 22.04, use the script “sudo apt install redis-server”. Moreover, you can configure the Redis server by editing the file named “/etc/redis/redis.conf”. In this post, the user experienced the installation and configuration of the Redis server on Ubuntu 22.04. Redis is a database used by many applications to store data as well as Redis is also used as a cache.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY