0
0
Redisquery~5 mins

Cluster creation in Redis

Choose your learning style9 modes available
Introduction

Creating a Redis cluster helps store data across multiple servers. This makes your data safe and your app faster.

You want to handle lots of data that one server can't store.
You want your app to keep working even if one server stops.
You want to spread the work so your app runs faster.
You want to add more servers easily as your app grows.
Syntax
Redis
redis-cli --cluster create <node1_ip>:<port> <node2_ip>:<port> ... --cluster-replicas <number_of_replicas>
Use the IP and port of each Redis node you want in the cluster.
The --cluster-replicas option sets how many replicas each master node has.
Examples
This creates a cluster with 3 nodes and no replicas.
Redis
redis-cli --cluster create 192.168.1.1:7000 192.168.1.2:7000 192.168.1.3:7000 --cluster-replicas 0
This creates a cluster with 4 nodes and no replicas.
Redis
redis-cli --cluster create 10.0.0.1:7000 10.0.0.2:7000 10.0.0.3:7000 10.0.0.4:7000 --cluster-replicas 0
Sample Program

This command creates a Redis cluster on your local machine using ports 7000, 7001, and 7002. There will be 3 master nodes with no replicas.

Redis
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0
OutputSuccess
Important Notes

Make sure all Redis nodes are running before creating the cluster.

All nodes should have cluster-enabled set to yes in their configuration.

Use different ports or IPs for each node to avoid conflicts.

Summary

Redis cluster creation spreads data across multiple servers for safety and speed.

Use the redis-cli with the --cluster create command and list all nodes.

Set replicas to keep copies of data for backup.