0
0
Redisquery~5 mins

Client-side cluster support in Redis

Choose your learning style9 modes available
Introduction
Client-side cluster support helps your application talk to the right Redis server in a group, so data is stored and found quickly.
When your app needs to handle lots of data spread across many Redis servers.
When you want faster responses by asking the right server directly.
When you want Redis to keep working even if one server stops.
When you want to add more Redis servers easily as your app grows.
Syntax
Redis
Use a Redis client library that supports cluster mode.
Connect using the cluster's startup nodes.
The client automatically routes commands to the right server.
You don't send commands to a single server; the client finds the right one.
Cluster nodes share data by slots; the client uses these slots to route commands.
Examples
Connect to a Redis cluster node on port 7000 using redis-cli with cluster support.
Redis
redis-cli -c -p 7000
Using ioredis in Node.js to connect to a Redis cluster and set/get a key.
Redis
const Redis = require('ioredis');
const cluster = new Redis.Cluster([
  { host: '127.0.0.1', port: 7000 },
  { host: '127.0.0.1', port: 7001 },
  { host: '127.0.0.1', port: 7002 }
]);

cluster.set('key', 'value');
cluster.get('key').then(console.log);
Sample Program
Connects to the Redis cluster node on port 7000, sets a key 'user:1' to 'Alice', then retrieves it.
Redis
redis-cli -c -p 7000
set user:1 "Alice"
get user:1
OutputSuccess
Important Notes
Make sure your Redis client library supports cluster mode before using it.
Cluster mode requires Redis servers to be set up as a cluster with slots assigned.
Client-side cluster support improves performance by reducing extra network hops.
Summary
Client-side cluster support lets your app talk directly to the right Redis server in a cluster.
It helps handle big data and keeps Redis fast and reliable.
Use a Redis client with cluster support and connect to multiple cluster nodes.