Within a server farm Redis can have multiple uses such as a fast cache or publish-subscribe system. In this guide we'll show how you can set up multiple servers to connect to a single central Redis instance. We will simulate a server farm using virtual machines.
This guide assumes that you already have Redis installed, but if you haven't yet find out how to install Redis in our knowledge base.
On production level instances we recommend using Linux, however for testing/development Windows can be used as well. For this guide we'll be using Windows Server 2016.
In order for our remote servers to connect to our central Redis instance we need to set 2 things:
Adding a firewall exception follows the same process that we covered in a previous guide, except this time we're going to add an inbound rule to allow incoming connection to port 6379 (the default port Redis uses).
To change Redis configuration, let's locate the Redis installation folder on the server it was installed on. When installed on Windows Redis automatically starts a service which uses 'redis.windows-service.conf' configuration file, therefore we're going to add changes to it:
Once opened, we're going to find and edit the
bind statement from using
127.0.0.1 to using the IP address of the server we're currently on. In our case our server IP is
10.0.1.20, thus we're going to change it to that. Be sure that your IP address is static and doesn't change over time, otherwise you'd have to constantly keep changing the configuration when sending and receiving data.
On Windows you can quickly check your IP address by running
ipconfigcommand in the command line.
Now, we'll restart Redis service for our changes to take place:
Now it's time to test if we can send messages to our Redis instance remotely. For this we're going to copy the 'redis-cli.exe' file from our Redis installation folder to our second server. This file will provide an interface to test our remote connection by sending a 'ping'.
We're going to open a command prompt and simply drag and drop the 'redis-cli.exe' file on it to get the executable file path, which we'll execute with the following commands
-h 10.0.1.20 -p 6379 ping. Note, how we're using
-h followed by the IP address of our Redis server and
-p with the port number we wish to send message through. This should result in a 'PONG' response from our Redis instance:
And now we have remote connection to our Redis server!