Redis Cluster Tutorial-3
Redis Cluster Tutorial-3
Create a redis.conf file inside each of the directories, from 7000 to 7005. As a template
for your configuration file just use the small example above, but make sure to replace
the port number 7000 with the right port number according to the directory name.
Now copy your redis-server executable, compiled from the latest sources in the
unstable branch at GitHub, into the cluster-test directory, and finally open 6 terminal
tabs in your favorite terminal application.
Start every instance like that, one every tab:
cd 7000
../redis-server ./redis.conf
As you can see from the logs of every instance, since no nodes.conf file existed, every
node assigns itself a new ID.
97a3a64667477371c4479320d683e4c8db5858b1
This ID will be used forever by this specific instance in order for the instance to have a
unique name in the context of the cluster. Every node remembers every other node
using this IDs, and not by IP or port. IP addresses and ports may change, but the
unique node identifier will never change for all the life of the node. We call this identifier
simply Node ID.
The first example, that is, the cluster creation, will be shown using both redis-cli in Redis
5 and redis-trib in Redis 3 and 4. However all the next examples will only use redis-cli,
since as you can see the syntax is very similar, and you can trivially change one
command line into the other by using redis-trib.rb help to get info about the old
syntax. Important: note that you can use Redis 5 redis-cli against Redis 4 clusters
without issues if you wish.
To create your cluster for Redis 5 with redis-cli simply type:
--cluster-replicas 1
The command used here is create, since we want to create a new cluster. The option --
cluster-replicas 1
means that we want a slave for every master created. The other
arguments are the list of addresses of the instances I want to use to create the new
cluster.
Obviously the only setup with our requirements is to create a cluster with 3 masters and
3 slaves.
Redis-cli will propose you a configuration. Accept the proposed configuration by
typing yes. The cluster will be configured and joined, which means, instances will be
bootstrapped into talking with each other. Finally, if everything went well, you'll see a
message like that:
This means that there is at least a master instance serving each of the 16384 slots
available.