Databases 7 min read

How to Set Up and Test a Redis 3 Cluster on Linux

This guide explains how Redis 3’s native clustering works, details the hash‑slot mechanism, and provides step‑by‑step instructions for installing Redis and its Ruby dependencies, configuring multiple nodes, creating a six‑node cluster, and testing key distribution across the cluster.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How to Set Up and Test a Redis 3 Cluster on Linux

Redis 3 now officially supports clustering, eliminating the need for third‑party proxies.

Redis clusters share data across multiple nodes, automatically partitioning keys into hash slots. Even if some nodes fail or lose communication, the cluster continues to serve requests.

How it works

Redis 3 cluster uses the concept of hash slots. A cluster contains 16384 slots; each node is responsible for a subset of slots. Adding or removing nodes simply involves moving slots between nodes.

Example: a three‑node cluster might assign slots 0‑5500 to node A, 5501‑11000 to node B, and 11001‑16383 to node C. To add node D, redistribute some slots from A, B, and C to D. To remove node A, move its slots to B and C before shutting it down. Slot migration is safe and does not block the cluster.

Installing Redis 3

Download the stable 3.0 version from http://www.redis.io/download and compile:

tar xzf redis-3.x.x.tar.gz
cd redis-3.x.x
make
cd src
make install

Copy the binaries:

cp /path/to/redis/src/redis-server /usr/local/bin
cp /path/to/redis/src/redis-cli /usr/local/bin
cp /path/to/redis/src/redis-trib.rb /usr/local/bin

Installing dependencies

Redis cluster commands are written in Ruby, so install Ruby and Rubygems:

yum -y install ruby ruby-rdoc
yum install rubygems

Install the Redis Ruby gem:

gem install -l redis-3.2.1.gem

Configuring the cluster

Create six Redis instances (three masters, three slaves) on ports 7000‑7005 and set up their configuration directories:

mkdir -p /data/cluster/7000 /data/cluster/7001 /data/cluster/7002 /data/cluster/7003 /data/cluster/7004 /data/cluster/7005

Copy the default redis.conf into each directory and edit the following settings:

port 7000
daemonize yes
appendonly yes
# enable clustering
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000

Repeat for ports 7001‑7005, adjusting the port value accordingly.

Start each instance:

cd /data/cluster/7000
redis-server redis.conf

Do the same for the other five instances and verify they are running (e.g., ps -ef | grep redis).

Creating the cluster

Run the cluster creation command:

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

Confirm the prompt by typing yes. The tool will assign all 16384 slots and report success.

Testing the cluster

Connect to a node and set a key:

redis-cli -p 7000
set clustertest 'hi'
get clustertest

Connect to another node without the -c flag and you will see a MOVED error indicating the key’s slot location. Using the -c flag automatically redirects the request:

redis-cli -c -p 7001
get clustertest

The command returns “hi”, confirming that the cluster correctly routes requests.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseClusterInstallation
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.