A full-featured desktop GUI client, RedisInsight is an essential tool for Redis developers. It is a lightweight multi-platform management visualization tool that helps you design, develop, and optimize your application capabilities in a single easy-to-use environment. RedisInsight not just makes it easier to interact with your databases and manage your data, but also helps in managing Redis Cluster with ease.
Redis Cluster is an active-passive cluster implementation that consists of master and replicas nodes. There are two kinds of nodes: master and replicas nodes. To get started with Redis Cluster, follow the below steps to build 3 Master and 3 Replicas.
Please Note: In Redis, slave nodes are generally called replicas as they hold the replicated slots that their masters have.
Follow this link to build Redis from source in your local system.
By default, if you compile Redis from source, you will find a simple bash script called create-cluster under /utils/ directory. In order to start a 6 nodes cluster with 3 masters and 3 replicas, just type the following commands:
To install RedisInsight on your local system, you need to first download the software from the Redis website.
Click this link to access a form that allows you to select the operating system of your choice.
Run the installer. After the web server starts, open http://YOUR_HOST_IP:8001 and add a Redis database connection.
Select "Connect to a Redis database"
Enter the requested details, including Name, Host (endpoint), Port, and Password. Then click “ADD REDIS DATABASE”.
Enter the details - host IP, port and name of the database of your choice.
On the left menu of the RedisInsight, click 'Cluster Management' option to check the cluster health and cluster nodes.
This view only contains information about the masters present in the Redis Cluster. The information present is - slot ranges, host, port and few metrics gathered from redis INFO Command.
Cluster Management comes with three different views to analyze your cluster architecture(as shown above).
- Master Layout - This view only contains information about the masters present in the Redis Cluster. The information present is - slot ranges, host, port and few metrics gathered from redis INFO Command.
- Master-Replica Layout - This view contains masters along with their replicas. This view contains information about slots ranges, host, port, etc for both master and replicas.
- Physical Layout - This view gives you a representation of your server i.e. it groups all nodes according to the physical server they reside in.
Resharding basically means to move hash slots from a set of nodes to another set of nodes, and like cluster creation it is accomplished using the redis-cli utility.
Typically, to start a resharding, you pass “--cluster reshard” option to the redis client CLI as shown below:
You only need to specify a single node, redis-cli will find the other nodes automatically.
With RedisInsight, it can be performed over the GUI. Open Cluster Management > Manual Resharding option > Destination node > Source Nodes and enter the slot range. Before we perform resharding, let us try to insert real-time keys into the cluster. You need to have ruby installed on your system
Save the above content in a file called testing.rb as shown below:
The above script will insert keys into the Redis cluster.
You can check the real-time logs via MONITOR command:
Let us perform a manual sharding. Select "Manual Sharding" under Actions tab. It will ask to select destination and source nodes. It allows to enter slot range too as shown below.
The resharding process begins instantly.
Finally, you can view the changes under the Cluster Management section as shown below:
This view gives you a representation of your Cluster nodes i.e. it groups all nodes according to the physical server they reside in.
Let us try to add a key against the cluster nodes
Once you set up a cluster, a cluster will have a sharding.
Once you add a key to Redis, hashes slot is calculated.Redis calculates the slot where the key is going to land by taking CRC16 of the key modulo 16384.
By Finding the hashes slot for the keys, your data will automatically be spread across the nodes.
In a Redis cluster, there are 16,384 slots available. The first master node in a cluster contain 0 to 5500, 5501 to 11000 and 3rd 11001 to 16,385
Let us add a new node in the Redis configuration file:
It's time to run the new Redis instance.
Enter the host and port details of the new node:
Now, you can view the nodes layout as shown below:
You can also view it via CLI on your local system if you want to verify the new node entry.
Whenever you add a new node, Redis allows you to rebalance your cluster as shown below:
You can select the master that will be replicas of the specific node:
Choose the right master node of your choice and click "Proceed".
To delete a node, select “Master-Replica Nodes” option and you will see all the replicas nodes
In order to upgrade the Redis process of one of the master nodes it is a good idea to failover it in order to turn it into a replicas with minimal impact on availability.
Also, RedisInsight Cluster Management tool allows you to rebalance your cluster by manually defining the slot coverage as shown below: