Skip to main content

Connect to Redis Replication

A Redis Replication database exposes two endpoints, and which one you connect to decides what happens to your application during a failover.

EndpointPortFormat
Primary endpoint6379{vip}:6379, for example 172.26.47.3:6379
Advanced endpoint26379{ip_node1}:26379,{ip_node2}:26379,{ip_node3}:26379

Read the Primary endpoint from the Overview tab of the database in the Console Portal.

Primary endpoint

The Primary endpoint always points at the current Redis Primary node, and it does not change when a failover occurs. Use it for standard Redis operations such as GET, SET, DEL, EXPIRE, and Pub/Sub.

It suits:

  • Standard application connectivity.
  • Simple Redis client implementations.
  • Systems that are not Sentinel-aware.

Advanced endpoint

The Advanced endpoint is a Redis Sentinel endpoint. Sentinel monitors the Redis nodes, detects failures, performs automatic failover, and provides service discovery to clients. When a failover happens, Sentinel publishes the new Primary and a Sentinel-aware client library reconnects to it on its own, with no configuration change on your side.

It suits:

  • High Availability environments.
  • Applications that must reconnect automatically after a failover.
  • Advanced Redis clients with Sentinel support.
  • Production environments that need topology awareness.

If your client library supports Sentinel, connect through the Advanced endpoint rather than the Primary endpoint.

Which endpoint should you use?

Use caseRecommended endpoint
Standard application connectivityPrimary endpoint
Applications using Sentinel-aware client librariesAdvanced endpoint
redis-cliPrimary endpoint

Connection examples

redis-cli

redis-cli is not Sentinel-aware. It connects to a single host and port at a time and cannot auto-discover Sentinel nodes, so connect it through the Primary endpoint.

redis-cli -h {vip} -p 6379 -a {redis_password}

Python (redis-py)

pip install redis
from redis.sentinel import Sentinel

sentinel = Sentinel(
[
("{ip_node1}", 26379),
("{ip_node2}", 26379),
("{ip_node3}", 26379),
],
socket_timeout=2,
)

redis_master = sentinel.master_for(
service_name="mymaster",
password="{redis_password}",
decode_responses=True,
)

redis_master.set("test", "hello")
print(redis_master.get("test"))

Node.js (ioredis)

npm install ioredis
const Redis = require("ioredis");

const redis = new Redis({
sentinels: [
{ host: "ip_node1", port: 26379 },
{ host: "ip_node2", port: 26379 },
{ host: "ip_node3", port: 26379 },
],
name: "mymaster",
password: "redis_password",
});

async function test() {
await redis.set("test", "hello");
const value = await redis.get("test");
console.log(value);
}

test();

Spring Boot

For Java Spring Boot applications, FPT recommends Spring Data Redis with either the Lettuce or Jedis client. Define the Sentinel master name and the list of Sentinel nodes in application.yml or application.properties.

spring:
data:
redis:
password: redis_password
sentinel:
master: mymaster
nodes:
- ip_node1:26379
- ip_node2:26379
- ip_node3:26379
spring.data.redis.password=redis_password
spring.data.redis.sentinel.master=mymaster
spring.data.redis.sentinel.nodes=ip_node1:26379,ip_node2:26379,ip_node3:26379
note

Older Spring Boot versions use the spring.redis.* prefix instead of spring.data.redis.*. Check which one applies to your version.

Next steps