Everything About Redis Installation and Configuration with Magento

Step 5: Binding to Remote Hosts

Remote Access

By default, the remote connection is not allowed in Redis as it is only accessible via localhost (i.e. 127.0.0.1). To connect the Redis server from remote hosts, follow the below steps.
Open the Redis configuration file in your preferred text editor.

sudo nano /etc/redis/redis.conf

Identify the command starts as bind 127.0.0.1 ::1 and replace the IP address 127.0.0.1 with 0.0.0.0

Output
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0::1

Now, restart the system for the changes to come into effect using the command:

sudo systemctl restart redis-server

To ensure that Redis is listening on all interfaces using the port 6379, run the following command:

ss -an | grep 6379

The output will be shown as the below,

Output
tcp  LISTEN 0   128 0.0.0.0:6379   0.0.0.0:*
tcp  LISTEN 0   128 [::]:6379      [::]:*

Enabling Firewall Rules

To enable the traffic from your remote hosts on port 6379, you need to set the firewall rules.
Let us assume that you want to allow access for the IP range, 192.168.121.0/24 then the command will be:

sudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379

Now your Redis server will be started to allow connections from the IP range, 192.168.121.0/24 (as set by you) on the TCP port 6379.

Step 6: Testing Redis

Now, that the Redis server has been installed and configured successfully, it is time to test whether the Redis server functions as expected. It is done by using some of the default commands such as,

Redis-cli ping pong commands

To test the connection between the Redis server, use the Redis command-line tool with a ping command.

redis-cli
127.0.0.1:6379> ping

It should respond with the output, PONG.

Output
PONG
127.0.0.1:6379>

Set value command

To check whether you can set values, use the command:

127.0.0.1:6379> set test “Welcome to Magemint!”
Output
OK

Now, to retrieve the value you set, use the command:

127.0.0.1:6379> get test

Output

“Welcome to Magemint!”

The above outputs confirm the successful functioning of the Redis server on your system. You can also test the fine-working of the Redis server using the below commands too.

  • redis info command
  • redis INFO clients command

Thus, from the above steps, you have learnt the how-to of installing, configuring and testing the fine-workings of Redis server on your Ubuntu system. Further, these are the basic process involved while configuring Redis on Ubuntu, to carry out other settings, refer to the official documentation of Redis, https://redis.io/documentation. It is necessary to note that the above-prescribed commands will vary from one operating system to another.  

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top