A Redis cluster is a distributed implementation of the Redis database that provides a way to run an automatically sharding, highly available Redis installation.
When you create a Redis Cluster, you start multiple Redis instances that each act as a node. To form a cluster, these nodes use a gossip protocol to communicate with each other and automatically distribute data between them. The distribution uses consistent hashing on the keys to divide the total key space (16384 slots by default) among all available nodes. Each member of the cluster handles a subset of the hashed keys.
Data in a Redis Cluster is partitioned across the nodes. Each master node is responsible for a portion of the data, and replica nodes duplicate this data for redundancy and failover protection. If a master node fails, one of its replicas can be promoted to take its place.
In terms of command execution, most Redis commands are redirected to the appropriate node automatically. But some commands, like multi-key operations, need all keys involved to be on the same node.
Here is a basic example of starting a new Redis Cluster with 3 master nodes and 3 slave nodes using redis-cli:
After starting the instances, you can use redis-cli to create a cluster:
Remember that a Redis Cluster provides automatic failover and high availability, but it does not provide strong consistency. Updates may take some time to propagate from master nodes to slave nodes. If a client reads from a slave node immediately after writing to the master, it might get an outdated value.