You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Redis中Traefik动态配置的格式及存储实体类型咨询

Traefik Redis 配置存储格式与实体类型说明

实体类型要求

Traefik 读取 Redis 中的配置时,仅支持哈希(Hash)类型,列表(List)、集合(Set)等其他类型无法被正确解析,会被直接忽略。

配置格式规则

  1. 哈希键(Key)前缀:默认使用 traefik/config/ 作为前缀,可通过 Traefik 的 redis.prefix 配置项自定义。每个哈希对应一个独立的配置单元(如路由、中间件、服务)。
  2. 字段(Field)与值(Value):
    • Field 为配置项的完整路径,例如 http.routers.my-router.entryPoints
    • Value 支持两种形式:简单字符串,或字符串化的 JSON 结构(复杂配置必须转成字符串存储,不能直接存入JSON对象)

示例操作(redis-cli)

# 存储一个基础路由配置
HSET traefik/config/my-router "http.routers.my-router.entryPoints" '["web"]'
HSET traefik/config/my-router "http.routers.my-router.rule" "Host(`example.com`)"
HSET traefik/config/my-router "http.routers.my-router.service" "my-service"

# 存储带负载均衡的服务配置
HSET traefik/config/my-service "http.services.my-service.loadBalancer.servers" '[{ "url": "http://192.168.1.100:8080" }, { "url": "http://192.168.1.101:8080" }]'

注意事项

  • Traefik 会定期轮询 Redis 中的哈希配置,检测到字段或值变化时自动加载更新。
  • 不要在同一前缀下混用不同 Redis 实体类型,否则会导致配置加载失败。

内容的提问来源于stack exchange,提问作者Michel Onstein

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 19:32:05