What is really the hype behind Redis? Redis has created a reputation for itself as the go-to data store. It is attributed as a key-value, in-memory, and open-source data store. These attributes make Redis an ideal message broker, cache, and database candidate/application.
Also, Redis’ resume illustrates its support for numerous data structures like Sets, Hashes, Lists, and Strings. Through features like automatic partitioning and Redis Sentinel, multiple Redis nodes and Redis Cluster provide high Redis availability.
Prerequisite
Be a sudoer/root user on the Ubuntu operating system you are using.
Installing Redis on Ubuntu
Make sure your Ubuntu operating system is up-to-date as it helps with the performance optimization of installed and yet-to-be-installed application packages.
$ sudo apt update && sudo apt upgrade -y
Next, run the following command to install Redis on your Ubuntu system.
$ sudo apt install redis-server -y
Once the installation process completes, confirm Redis installed version on your system.
$ redis-server --version
Next, enable and check Redis’s status to be sure it is up and running.
$ sudo systemctl enable redis-server $ sudo systemctl status redis-server
Configuring Redis on Ubuntu
Now that we have installed and confirmed that Redis is up and running, it is time to implement some important configurations. The default installation of Redis does not permit remote connections. Redis’ default configuration only permits localhost (127.0.0.1) connections on the machine hosting it.
You do not need to enable remote access/connection on your Redis configuration if you have a single server setup. However, if for some reason a separate/remote server setup is running Redis, you will need to configure it to handle remote connections.
The following command should open Redis’ main configuration file on your Ubuntu system:
$ sudo nano /etc/redis/redis.conf
Trace the following sections on the file:
This section demonstrates how to bind Redis to all or specific remote machines’ IP addresses. For instance, if we want any remote user to be able to access this Redis server, we will edit out or comment on the line bind 127.0.0.1 ::1
and replace it with bind 0.0.0.0 ::1
.
For the implemented configuration changes to be effective, restart the Redis server.
$ sudo systemctl restart redis-server
Next, verify that all Redis is listening to its associated interfaces.
$ ss -an | grep 6379
Since Redis communicates via port 6379, your firewall (if active) should be configured to allow traffic through this port.
$ sudo ufw allow 6379/tcp $ sudo ufw reload $ sudo ufw status
Testing Redis Remote Connection
On the remote machine that wishes to connect to the Redis server, install redis-tools to facilitate this client-to-server communication.
$ sudo apt install redis-tools -y
Next, we will now use the redis-cli utility to ping the Redis server via IP address.
$ redis-cli -h 192.168.100.23 ping
The output PONG confirms that the two remote computers can communicate with one another.
This article has walked us through the installation, configuration, and testing of the Redis server on Ubuntu. For a more thorough Redis configuration guide, reference the file /etc/redis/redis.conf.
Redis also works very well in a docker container…