Redis Cluster¶
Redis Cluster shards data across multiple nodes automatically (via hash slots) and provides replica-based failover per shard — conceptually closer to MongoDB sharding than to a single-writer replication setup. Reference: Redis Cluster Tutorial. See Overview for base install.
Install Redis Server (on Each Node)¶
apt-get -y install redis-server
systemctl enable redis-server
systemctl start redis-server
redis-cli
127.0.0.1:6379> ping
PONG
Install Ruby¶
Older Redis Cluster tooling (redis-trib.rb) is Ruby-based:
apt-get -y install ruby ruby-redis
Modern Redis versions (5+) fold cluster management directly into redis-cli via redis-cli --cluster ..., making the separate Ruby tool unnecessary — check redis-cli --cluster help on your installed version before reaching for redis-trib.rb, which is deprecated on recent releases.
Local Test Cluster via the Bundled Script¶
For building and testing a cluster entirely on one machine (multiple Redis processes on different ports) rather than across real hosts:
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zvxf redis-3.2.8.tar.gz
cd ~/redis-3.2.8/utils/create-cluster
./create-cluster create
This is pinned to an old release for format reference — grab a current Redis release instead; the utils/create-cluster script's usage has stayed conceptually the same across versions (create, start, stop, clean subcommands), but check the version you actually download for any option changes.
For a Real Multi-Host Cluster¶
The bundled script above is single-host only. Standing up a genuine multi-node cluster follows the same shape but across real hosts:
- Start
redis-serveron each node withcluster-enabled yesin its config, plus a uniquecluster-config-filepath - Open the cluster bus port (the node's normal port + 10000 — e.g.
6379and16379) between all nodes, not just the client-facing port - Use
redis-cli --cluster create <node1_ip>:6379 <node2_ip>:6379 ... --cluster-replicas 1to form the cluster and assign replicas automatically
Not exercised in the source notes for this page — the official cluster tutorial walks through the multi-host case in full and is worth following directly rather than working from a paraphrase here, since the exact flags have shifted across Redis versions.
Related¶
- CLI Basics — the same commands apply once connected to any cluster node, with the caveat that multi-key operations (
MSET, transactions, Lua scripts touching multiple keys) only work if all involved keys hash to the same slot