tencent cloud

Tencent Cloud Distributed Cache (Redis OSS-Compatible)

Release Notes and Announcements
Release Notes
Announcements
User Tutorial
Product Introduction
Overview
Product Strengths
Use Cases
Storage Engine
Product Series
Product Versions
Specifications and Performance
Read/Write Separation
Multi-AZ Deployment
Regions and AZs
Terms
Service Regions and Service Providers
Purchase Guide
Billing Overview
Pricing Center
Instance Purchasing
Renewal (Yearly/Monthly Subscription)
Refund (Yearly/Monthly Subscription)
Overdue Payments
Switching from Pay-as-You-Go to Yearly/Monthly Subscription
Getting Started
Quickly Creating an Instance
Connecting to an Instance (Redis/Valkey Edition)
Operation Guide
Operation Overview
Connecting to a Database Instance
Managing Instances
Upgrade Instance
Management Node (Redis/ValKey Edition)
Multi-AZ Deployment Management
Backup and Restoration
Managing Accounts
Parameter Configuration
Slow Query
Access Management
Network and Security
Monitoring and Alarms
Event Management (Redis/ValKey Edition)
Data Migration
Global Replication for Redis Edition
Database Audit
Performance Optimization
Sentinel Mode
Development Guidelines
Naming Rules
Basic Usage Guidelines
Design Principles of Key and Value
Command Usage Guidelines
Design Principles of Client Programs
Connection Pool Configuration
Command Reference
Command Reference Overview
Redis Edition and Valkey Edition Command Compatibility
Version Command Usage Differences
Differences Between the Proxy Architecture and Direct Connection Mode
More Command Operations (Redis/Valkey Edition)
Memcached Edition Command Compatibility
Practical Tutorial
Building TencentDB for Redis® Client Monitoring Based on Spring Boot
Redis Client Connection Configuration Policy and Practice
Global SCAN Guide for Cluster Architecture
Eliminating Instances Securely
Hot Key and Big Key
AZ Migration Scheme
Troubleshooting
Connection Exception
Exception Analysis and Solution of Redisson Client Timeout Reconnection
Performance Troubleshooting and Fine-Tuning
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Parameter Management APIs
Other APIs
Backup and Restoration APIs
Region APIs
Monitoring and Management APIs
Log APIs
Data Types
Error Codes
FAQs
General
Connection and Login
Purchase
Service Agreement
Service Level Agreement
Terms of Service
Glossary
Contact Us

Sentinel Mode

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-03-17 18:10:58

Overview

Sentinel is a standalone process that monitors the master and replica nodes in a Tencent Cloud Distributed Cache cluster. When the master node fails, Sentinel can elect a new master from the replica nodes to replace it automatically. This high-availability solution ensures that business operations run smoothly.
Note:
The Memcached Edition does not support Sentinel mode.

Sentinel Commands

Tencent Cloud Distributed Cache 4.0 and later support the Sentinel mode by default. You can use the following Sentinel commands.

SENTINEL sentinels

This command lists the sentinels information of the monitored master.

Command format

SENTINEL sentinels <any name>

Sample code



SENTINEL get-master-addr-by-name

This command gets the IP address information of the master-name.

Command format

SENTINEL get-master-addr-by-name <any name>

Sample code



Connection Sample for the Sentinel Mode

Prerequisites

The Tencent Cloud Distributed Cache instance Redis version is 4.0 or 5.0.
The database instance is in the Running status.
Get the Private IPv4 Address and Port information for database connection in the Network Info section on the Instance Details page in the Tencent Cloud Distributed Cache console. For detailed directions, see Viewing Instance Information.
Get the account and password for database access. For detailed directions, see Managing Account.
Download and install Jedis. The latest version is recommended.

Connection sample

The following sample code takes Jedis 3.6.0 as an example. The latest version is recommended.
The Jedis version is 3.6.0 or later.
The Lettuce version is 5.3.0.RELEASE or later.
The Spring Data Redis version is 2.5.1 or later, for which the spring.redis.sentinel.password parameter should be configured.
You need to modify the parameters based on the comments, including IP, port, account, and password for database access.

Connection via Java

package com.example.demo;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

public class Main {
public static void main(String[] args) {
String masterName = "test";
Set<String> sentinels = new HashSet<>();
// You need to configure the database instance's private IPv4 address and port
sentinels.add("XX.XX.XX.XX:6379");
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
String dbPassword = "root:xxx";//Replace this with your database access password
String sentinelPassword = "root:xxx";//Replace this with your database access password

JedisSentinelPool jedisSentinelPool =
new JedisSentinelPool(masterName, sentinels, poolConfig,
2000, 2000, dbPassword,
0, null, 2000, 2000,
sentinelPassword, null);
System.out.println("jedisSentinelPool.getResource().ping() = " + jedisSentinelPool.getResource().ping());
jedisSentinelPool.close();
}
}

Connection via the Spring Data framework

package com.example.demo;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import redis.clients.jedis.JedisPoolConfig;

@SpringBootApplication

public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

@Configuration
class RedisConfig {
@Bean
@Qualifier("jedisConnectionFactory")
public JedisConnectionFactory connectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
.master("test")
.sentinel("XX.XX.XX.XX", 6379);//Replace this with the private IPv4 address and port of your database instance
sentinelConfig.setPassword(RedisPassword.of("xxx"));//Replace this with your database access password
sentinelConfig.setSentinelPassword(RedisPassword.of("xxx"));//Replace this with your database access password
JedisPoolConfig poolConfig = new JedisPoolConfig();
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(sentinelConfig, poolConfig);
connectionFactory.afterPropertiesSet();
return connectionFactory;
}

@Bean
@ConditionalOnBean(JedisConnectionFactory.class)
public RedisTemplate<String, String> redisTemplate(@Qualifier("jedisConnectionFactory") JedisConnectionFactory factory) {
RedisTemplate<String, String> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.afterPropertiesSet();
//test
template.opsForValue().set("test", "test1");
System.out.println("template.opsForValue().get(\\"test\\") = " + template.opsForValue().get("test"));
return template;
}

}

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백