我正在尝试配置 redisson.yaml 如下所示
redis:
mode: ${REDIS_MODE:single} # Default to single mode if REDIS_MODE is not set
# Configuration for single Redis server
singleServerConfig:
enabled: ${REDIS_MODE:single} == 'single'
address: ${REDIS_URL:-redis://localhost:6379}
username: ${REDIS_USERNAME:-null}
password: ${REDIS_PASSWORD:-null}
database: ${REDIS_DATABASE:-0}
# Configuration for Redis cluster
clusterServersConfig:
enabled: ${REDIS_MODE:single} == 'cluster'
nodeAddresses:
- ${REDIS_URL:-redis://localhost:6379}
# Add more nodes if available
password: ${REDIS_PASSWORD:-null}
但它给出了错误 引起:com.fasterxml.jackson.core.JsonParseException:意外字符('#'(代码 35)):需要一个有效值(JSON 字符串、数字、数组、对象或标记“null”、“true”或“错误的') 在 [Source: (String)"# Common Redis 配置(如果有) 雷迪斯: 模式:${REDIS_MODE:单}
那么我们如何在 redisson.yaml 文件中启用条件检查以根据环境变量加载 redis 配置?
Yaml 不支持条件,所以我认为技巧是使用两个环境变量作为布尔开关,比如:REDIS_SINGLE_ENABLED 和 REDIS_CLUSTER_ENABLED
clusterServersConfig:
enabled: ${REDIS_CLUSTER_ENABLED}
还要删除
mode: ${REDIS_MODE:single}
前面的注释,我认为您的错误来自“#”。
Unexpected character ('#' (code 35)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"# Common Redis configuration (if any) **redis: mode: ${REDIS_MODE:single}