Redis Cluster data sharding
Redis Cluster does not use consistent hashing, but a different form of sharding where every key is conceptually part of what we call an hash slot. hash槽
There are 16384 hash slots in Redis Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384.
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
The command used here is create, since we want to create a new cluster. The option --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.