redis-connection
This section describes how client applications connect to an Redis Replication cluster.
FPT Database Engine provides two endpoint types for Redis Replication clusters:
- Primary endpoint :Standard Redis endpoint for application connections over port 6379 , in the format: {vip}:6379. Example: 172.26.47.3:6379. Users can retrieve this endpoint from the Overview page of the database cluster in the Console Portal.
- Advanced endpoint : Redis Sentinel endpoint used for service discovery and failover handling. Applications connect to Sentinel nodes over port 26379 , in the format: {ip_node1}:26379,{ip_node2}:26379,{ip_node3}:26379. Example: 192.168.47.10:26379,192.168.47.20:26379,192.168.47.30:26379.
1. Primary endpoint
The Primary endpoint always points to the current Redis Primary node. This endpoint remains unchanged even when a failover occurs.
Applications can use this endpoint for standard Redis operations such as: GET, SET, DEL, EXPIRE, Pub/Sub.
Recommended use cases:
- Standard application connectivity.
- Simple Redis client implementations.
- Systems that do not require Sentinel-aware configuration.
2. Advanced endpoint
Redis Sentinel is responsible for monitoring Redis nodes, detecting failures, performing automatic failover, and providing service discovery for Redis clients. Sentinel enables applications to automatically connect to the active Redis Primary node without requiring configuration changes during failover events.
The Advanced endpoint is a Redis Sentinel endpoint used for:
- Service discovery.
- Automatic failover handling.
- Dynamic Primary node detection.
Applications using Sentinel-aware Redis client libraries should connect through the Advanced endpoint instead of the Primary endpoint. When a failover occurs, Sentinel updates the new Primary node information and Sentinel-aware client libraries automatically reconnect using the updated topology.
Recommended use cases:
- High Availability (HA) environments.
- Applications requiring automatic reconnection after failover.
- Advanced Redis clients with Sentinel support.
- Production environments requiring topology awareness.
3. Connection guidelines for client libraries
3.1. redis-cli
redis-cli is not a Sentinel-aware client library. It can only connect to a single host and port at a time and does not support multi-Sentinel auto-discovery like application libraries. Therefore, when using redis-cli, customers should connect through the Primary endpoint.
redis-cli -h {vip} -p 6379 -a {redis_password}
3.2. 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"))
3.3. 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();
3.3. Spring Boot
spring: data: redis: password: redis_password sentinel: master: mymaster nodes: - ip_node1:26379 - ip_node2:26379 - ip_node3:26379
3.4. Java Spring Boot
For Java Spring Boot applications, FPT recommends using Spring Data Redis with either the Lettuce or Jedis client. The recommended configuration is to define Sentinel master-name and list of Sentinel nodes inside application.yml or application.properties.
# application.properties 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
Older Spring Boot versions may use the configuration prefix spring.redis.* instead of spring.data.redis.*. Customers should verify the correct configuration format based on their Spring Boot version.
4. Which endpoint should you use?
| Use case | Recommended endpoint |
|---|---|
| Standard application connectivity | Primary endpoint |
| Applications using Sentinel-aware client libraries | Advanced endpoint |
| redis-cli | Primary endpoint |