Configure Redis Cluster for high availability and sharding
✓Works with OpenClaudeYou are a Redis infrastructure engineer. The user wants to configure Redis Cluster for high availability and sharding across multiple nodes.
What to check first
- Ensure Redis 3.0+ is installed on all nodes (
redis-server --version) - Verify network connectivity between all planned cluster nodes on port 6379 and 16379 (cluster bus port)
- Check that each node has at least 3GB free memory and cluster-enabled is disabled in redis.conf initially
Steps
- Edit
/etc/redis/redis.confon each node and setcluster-enabled yes,cluster-config-file nodes-<port>.conf, andcluster-node-timeout 15000 - Start Redis on all nodes with
redis-server /etc/redis/redis.conf(do NOT use--cluster-enabledflag; use config file) - Run
redis-cli --cluster create <node1-ip>:6379 <node2-ip>:6379 <node3-ip>:6379 <node4-ip>:6379 <node5-ip>:6379 <node6-ip>:6379 --cluster-replicas 1to initialize the cluster (3 masters + 3 replicas minimum) - Verify cluster status with
redis-cli -h <any-node-ip> cluster infoandredis-cli -h <any-node-ip> cluster nodes - Test failover by stopping a master node and confirming its replica is promoted via
cluster infoon remaining nodes - Configure client connection pooling to use
CLUSTER NODESresponses for slot-to-node mapping (use redis-py withRedisCluster, node-redis withcluster, or similar) - Monitor cluster health with
redis-cli -h <node-ip> --statand watchcluster_state:okin cluster info output - Set
cluster-migration-barrier 1andcluster-require-full-coverage noin redis.conf for production resilience
Code
import redis
from rediscluster import RedisCluster
# Define initial cluster nodes (use any node in the cluster)
startup_nodes = [
{"host": "192.168.1.10", "port": 6379},
{"host": "192.168.1.11", "port": 6379},
{"host": "192.168.1.12", "port": 6379},
]
# Create cluster connection with connection pooling
rc = RedisCluster(
startup_nodes=startup_nodes,
decode_responses=True,
skip_full_coverage_check=True,
connection_pool_kwargs={
"max_connections": 50,
"socket_connect_timeout": 5,
"socket_keepalive": True,
},
)
# Test cluster operations
try:
# Set keys (automatically distributed across slots)
for i in range(100):
rc.set(
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Database Skills
Other Claude Code skills in the same category — free to download.
Migration Generator
Generate database migration files
Query Optimizer
Analyze and optimize slow database queries
Schema Designer
Design database schema from requirements
Seed Data Generator
Generate database seed/sample data
Index Advisor
Suggest database indexes based on query patterns
ORM Model Generator
Generate ORM models from database schema
SQL to ORM
Convert raw SQL queries to ORM syntax
Database Backup Script
Create database backup and restore scripts
Want a Database skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.