0
0
Redisquery~5 mins

Cluster architecture in Redis

Choose your learning style9 modes available
Introduction

Cluster architecture helps Redis store and manage data across many servers. This makes Redis faster and able to handle more data.

When your data is too big to fit on one Redis server.
When you want Redis to keep working even if one server stops.
When you want to spread the work of handling many users across servers.
When you want Redis to automatically balance data between servers.
When you want to add more servers easily as your data grows.
Syntax
Redis
No direct query syntax; cluster setup is done by configuring multiple Redis nodes and connecting them.
Redis Cluster uses multiple Redis nodes working together.
Data is split into 16384 slots, each node holds some slots.
Examples
This command starts a Redis node on port 7000 with cluster mode on.
Redis
# Example: Start Redis nodes with cluster enabled
redis-server --port 7000 --cluster-enabled yes --cluster-config-file nodes-7000.conf --cluster-node-timeout 5000 --appendonly yes
This command connects the nodes into a cluster with replicas for failover.
Redis
# Create a cluster with 3 master nodes and 3 replicas
redis-cli --cluster create 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 --cluster-replicas 1
Sample Program

This example sets a key in the cluster and gets it back, showing data is shared across nodes.

Redis
# Connect to Redis cluster and set a key
redis-cli -c -p 7000 SET user:1 "Alice"
redis-cli -c -p 7000 GET user:1
OutputSuccess
Important Notes

Redis Cluster automatically redirects commands to the right node using hash slots.

Clients must support cluster mode to follow redirects.

Cluster helps with high availability and scaling but adds some complexity.

Summary

Redis Cluster splits data across multiple servers using hash slots.

It improves speed, storage, and fault tolerance.

Setting up a cluster involves starting nodes with cluster enabled and linking them.