爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      redis哨兵客户端文档

      首页 知识中心 云端实践 文章详情页

      redis哨兵客户端文档

      2023-06-12 09:39:03 阅读次数:468

      master,redis,sentinel

      Sentinel client spec

      How to build clients for Redis Sentinel

      Redis Sentinel is a monitoring solution for Redis instances that handles automatic failover of Redis masters and service discovery (who is the current master for a given group of instances?). Since Sentinel is both responsible for reconfiguring instances during failovers, and providing configurations to clients connecting to Redis masters or replicas, clients are required to have explicit support for Redis Sentinel.

      This document is targeted at Redis clients developers that want to support Sentinel in their clients implementation with the following goals:

      • Automatic configuration of clients via Sentinel.
      • Improved safety of Redis Sentinel automatic failover.

      For details about how Redis Sentinel works, please check the ​​Redis Documentation​​, as this document only contains information needed for Redis client developers, and it is expected that readers are familiar with the way Redis Sentinel works.

      Redis service discovery via Sentinel

      Redis Sentinel identifies every master with a name like "stats" or "cache". Every name actually identifies a group of instances, composed of a master and a variable number of replicas.

      The address of the Redis master that is used for a specific purpose inside a network may change after events like an automatic failover, a manually triggered failover (for instance in order to upgrade a Redis instance), and other reasons.

      Normally Redis clients have some kind of hard-coded configuration that specifies the address of a Redis master instance within a network as IP address and port number. However if the master address changes, manual intervention in every client is needed.

      A Redis client supporting Sentinel can automatically discover the address of a Redis master from the master name using Redis Sentinel. So instead of a hard coded IP address and port, a client supporting Sentinel should optionally be able to take as input:

      • A list of ip:port pairs pointing to known Sentinel instances.
      • The name of the service, like "cache" or "timelines".

      This is the procedure a client should follow in order to obtain the master address starting from the list of Sentinels and the service name.

      Step 1: connecting to the first Sentinel

      The client should iterate the list of Sentinel addresses. For every address it should try to connect to the Sentinel, using a short timeout (in the order of a few hundreds of milliseconds). On errors or timeouts the next Sentinel address should be tried.

      If all the Sentinel addresses were tried without success, an error should be returned to the client.

      The first Sentinel replying to the client request should be put at the start of the list, so that at the next reconnection, we'll try first the Sentinel that was reachable in the previous connection attempt, minimizing latency.

      Step 2: ask for master address

      Once a connection with a Sentinel is established, the client should retry to execute the following command on the Sentinel:

      SENTINEL get-master-addr-by-name master-name

      Where master-name should be replaced with the actual service name specified by the user.

      The result from this call can be one of the following two replies:

      • An ip:port pair.
      • A null reply. This means Sentinel does not know this master.

      If an ip:port pair is received, this address should be used to connect to the Redis master. Otherwise if a null reply is received, the client should try the next Sentinel in the list.

      Step 3: call the ROLE command in the target instance

      Once the client discovered the address of the master instance, it should attempt a connection with the master, and call the ​​ROLE​​ command in order to verify the role of the instance is actually a master.

      If the ​​ROLE​​​ commands is not available (it was introduced in Redis 2.8.12), a client may resort to the ​​INFO replication​​​ command parsing the ​​role:​​ field of the output.

      If the instance is not a master as expected, the client should wait a short amount of time (a few hundreds of milliseconds) and should try again starting from Step 1.

      Handling reconnections

      Once the service name is resolved into the master address and a connection is established with the Redis master instance, every time a reconnection is needed, the client should resolve again the address using Sentinels restarting from Step 1. For instance Sentinel should contacted again the following cases:

      • If the client reconnects after a timeout or socket error.
      • If the client reconnects because it was explicitly closed or reconnected by the user.

      In the above cases and any other case where the client lost the connection with the Redis server, the client should resolve the master address again.

      Sentinel failover disconnection

      Starting with Redis 2.8.12, when Redis Sentinel changes the configuration of an instance, for example promoting a replica to a master, demoting a master to replicate to the new master after a failover, or simply changing the master address of a stale replica instance, it sends a ​​CLIENT KILL type normal​​ command to the instance in order to make sure all the clients are disconnected from the reconfigured instance. This will force clients to resolve the master address again.

      If the client will contact a Sentinel with yet not updated information, the verification of the Redis instance role via the ​​ROLE​​ command will fail, allowing the client to detect that the contacted Sentinel provided stale information, and will try again.

      Note: it is possible that a stale master returns online at the same time a client contacts a stale Sentinel instance, so the client may connect with a stale master, and yet the ROLE output will match. However when the master is back again Sentinel will try to demote it to replica, triggering a new disconnection. The same reasoning applies to connecting to stale replicas that will get reconfigured to replicate with a different master.

      Connecting to replicas

      Sometimes clients are interested to connect to replicas, for example in order to scale read requests. This protocol supports connecting to replicas by modifying step 2 slightly. Instead of calling the following command:

      SENTINEL get-master-addr-by-name master-name

      The clients should call instead:

      SENTINEL replicas master-name

      In order to retrieve a list of replica instances.

      Symmetrically the client should verify with the ​​ROLE​​ command that the instance is actually a replica, in order to avoid scaling read queries with the master.

      Connection pools

      For clients implementing connection pools, on reconnection of a single connection, the Sentinel should be contacted again, and in case of a master address change all the existing connections should be closed and connected to the new address.

      Error reporting

      The client should correctly return the information to the user in case of errors. Specifically:

      • If no Sentinel can be contacted (so that the client was never able to get the reply to​​SENTINEL get-master-addr-by-name​​), an error that clearly states that Redis Sentinel is unreachable should be returned.
      • If all the Sentinels in the pool replied with a null reply, the user should be informed with an error that Sentinels don't know this master name.

      Sentinels list automatic refresh

      Optionally once a successful reply to ​​get-master-addr-by-name​​ is received, a client may update its internal list of Sentinel nodes following this procedure:

      • Obtain a list of other Sentinels for this master using the command​​SENTINEL sentinels <master-name>​​.
      • Add every ip:port pair not already existing in our list at the end of the list.

      It is not needed for a client to be able to make the list persistent updating its own configuration. The ability to upgrade the in-memory representation of the list of Sentinels can be already useful to improve reliability.

      Subscribe to Sentinel events to improve responsiveness

      The ​​Sentinel documentation​​ shows how clients can connect to Sentinel instances using Pub/Sub in order to subscribe to changes in the Redis instances configurations.

      This mechanism can be used in order to speedup the reconfiguration of clients, that is, clients may listen to Pub/Sub in order to know when a configuration change happened in order to run the three steps protocol explained in this document in order to resolve the new Redis master (or replica) address.

      However update messages received via Pub/Sub should not substitute the above procedure, since there is no guarantee that a client is able to receive all the update messages.

      Additional information

      For additional information or to discuss specific aspects of this guidelines, please drop a message to the ​​Redis Google Group​​.

      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/adofsauron/5707995,作者:帝尊悟世,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:Linux之sshd_config配置文件说明及实践

      下一篇:python中Flask框架介绍

      相关文章

      2025-05-06 09:19:12

      redis高可用集群搭建

      redis高可用集群搭建

      2025-05-06 09:19:12
      master , redis , 服务器 , 节点 , 集群
      2025-04-22 09:27:37

      【Redis】浅析 Redis 事务

      【Redis】浅析 Redis 事务

      2025-04-22 09:27:37
      redis , Redis , 事务 , 命令 , 执行
      2025-04-09 09:13:17

      解决tomcat部署项目中碰到的几个问题

      在tomcat上部署项目并进行测试,经常会碰到各种问题。在不同的操作系统上部署,对问题的解决也会有一些差异。

      2025-04-09 09:13:17
      data , redis , tomcat , 信息
      2025-04-09 09:11:38

      redis配置参数详细说明

      redis配置参数详细说明

      2025-04-09 09:11:38
      conf , redis , server , 默认
      2025-03-26 09:31:37

      Redis的发布订阅(消息队列,比如ActiveMQ,一方得到数据后,多方得到信息)

      发布和订阅是进程间的一种消息通信模式:发送者(publisher)将消息发送给一个第三方,订阅者(subscriber)从第三方那里接收消息。

      2025-03-26 09:31:37
      redis
      2025-03-24 08:46:07

      idea2023的git从dev分支合并到主分支master

      idea2023的git从dev分支合并到主分支master

      2025-03-24 08:46:07
      dev , git , master , 分支 , 远程
      2025-03-18 08:27:10

      lepus监控redis执行python check_redis.py报错

      lepus监控redis执行python check_redis.py报错

      2025-03-18 08:27:10
      redis
      2025-03-17 07:49:59

      非openresty方式安装Nginx + Lua + Redis 环境

      非openresty方式安装Nginx + Lua + Redis 环境

      2025-03-17 07:49:59
      lua , nginx , Nginx , redis , 模块
      2025-03-17 07:49:59

      redis-cluster分布式集群安装部署

      redis-cluster分布式集群安装部署

      2025-03-17 07:49:59
      redis , Ruby , 安装 , 实例 , 集群
      2025-02-26 07:21:36

      简述Redis事务实现--------->负载均衡算法、类型

      MULTI命令的执行,标识着一个事务的开始。MULTI命令会将客户端状态的flag属性中打开REDIS_MULTI标识来完成的。

      2025-02-26 07:21:36
      redis , Redis , 事务 , 命令 , 客户端 , 服务器 , 节点
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5239298

      查看更多

      最新文章

      简述Redis事务实现--------->负载均衡算法、类型

      2025-02-26 07:21:36

      Redis【web应用实践_网页缓存、其他功能(发布与订阅、慢查询 、流水线pipeline)】(四)-全面详解

      2024-09-25 10:15:32

      neptune节点的客户端测试程序

      2024-09-24 06:30:20

      Redis客户端管理神器RedisInsight 推荐|8月更文挑战

      2024-07-01 01:33:26

      用户登录,保存30天的免登,只允许两个设备登录,如果有第三个设备登录,踢掉第一个。改密码的时候,所有设备需要下线。这个逻辑怎么实现呢?

      2024-05-09 09:19:54

      深入学习 Redis - 基于 Jedis 通过 Java 客户端操作 Redis 和 Redis 集群

      2024-03-29 09:52:02

      查看更多

      热门文章

      redis客户端连接(error) NOAUTH Authentication required

      2023-02-13 07:59:59

      redis-启动服务端-客户端连接服务端

      2023-03-29 10:07:17

      Scrapy_redis框架的概念作用和流程

      2023-06-07 07:30:58

      一线互联网大厂都是怎么面试Redis 审核中

      2023-06-13 08:36:00

      客户端快速启动redis

      2023-08-09 06:47:35

      Redis【web应用实践_网页缓存、其他功能(发布与订阅、慢查询 、流水线pipeline)】(四)-全面详解

      2024-09-25 10:15:32

      查看更多

      热门标签

      客户端 实践 基础知识 Java 服务器 java 数据库 框架 python 服务端 学习 代码 简单 javascript 编程
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      redis-启动服务端-客户端连接服务端

      一线互联网大厂都是怎么面试Redis 审核中

      redis客户端连接(error) NOAUTH Authentication required

      redis集群实践+等保要求的整改方案

      Scrapy_redis框架的概念作用和流程

      用户登录,保存30天的免登,只允许两个设备登录,如果有第三个设备登录,踢掉第一个。改密码的时候,所有设备需要下线。这个逻辑怎么实现呢?

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号