跳到主要内容

Redis HA

Aidy Gateway 目前所有的 Redis 均支持使用 Redis Sentinel 作为高可用方案。

[!NOTE] 因 Aidy Gateway 的相关能力强依赖 Redis Script,因此不支持 Redis Cluster 作为高可用方案。

支持矩阵

Redis 部署模式动态配置入口限流上游限流说明
单实例 / 主从(固定地址)支持支持支持使用 redis://host:port/db[?key=...]
Sentinel支持支持支持使用 redis+sentinel://sentinel1:26380,sentinel2:26380/db?master=<master-name>
Redis Cluster(分片)不支持不支持不支持-

Sentinel 配置

URL 格式

Sentinel 模式统一使用如下连接串:

redis+sentinel://[username:password@]sentinel1:26380,sentinel2:26380,sentinel3:26380/db?master=<master-name>[&key=<redis-key>][&sentinel_username=<user>][&sentinel_password=<pass>]

说明:

  • sentinel1:26380,sentinel2:26380,... 填的是 Sentinel 节点地址,不是 Redis master 的业务端口。
  • master 必填,表示 Sentinel 中登记的 master name。
  • db 为 Redis database 编号;未指定时默认为 0
  • key 仅动态配置会用到;限流无需填写。
  • URL 中的 username / password 用于 Redis 数据节点认证。
  • Sentinel 默认不使用认证信息,若 Sentinel 本身开启了认证,需显式通过 sentinel_username / sentinel_password 指定。

配置示例

动态配置(Redis V2)

[dynamic-config]
source = "redis"
redis = "redis+sentinel://1.1.1.1:26380,2.2.2.2:26380,3.3.3.3:26380/0?master=<master-name>&key=aidy-gateway-config-v2"
enable_redis_v2 = true
debounce = "5s"

限流存储

[rate-limit]
redis = "redis+sentinel://1.1.1.1:26380,2.2.2.2:26380,3.3.3.3:26380/1?master=<master-name>"
headers_mode = "on-limit"

备注

在使用 Sentinel 模式时,目前 Aidy Gateway 始终会连接到 Master 节点(即使是读请求,也不会连接到 Slave 节点)。

Dynamic Config 的 Redis Watch Loop 依赖于 Redis Keyspace Notifications 能力,因此在切换主节点时会执行一次全量配置重载 + 重新订阅,这可能导致短暂的配置更新延迟。