feat: support redis multi mode#1788
Conversation
Greptile SummaryThis PR replaces the single-node Redis client (
Confidence Score: 3/5The core client logic and backward compatibility are solid, but two pre-existing regressions from earlier review rounds remain unresolved in client.go, and the new documentation deployment example actively misleads users by placing all three mode configs under the same YAML block with conflicting duplicate keys. The duplicate-key documentation bug is not merely cosmetic — a user following the deployment guide and copying the combined block would silently connect to cluster mode regardless of intent. The two client.go issues flagged in prior rounds (TLSInsecureSkipVerify regression for rediss:// + config flag, and undetected unknown URL params) also remain open. The implementation itself is architecturally sound and well-tested. docs/en/deployment/configuration.md and docs/zh/deployment/configuration.md (duplicate-key deployment example); internal/pkg/xredis/client.go (open regressions from prior review rounds) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[NewClient cfg] --> B[newUniversalOptions cfg]
B --> C[ParseUniversalURL cfg.URL]
C --> D{URL empty?}
D -- yes --> E[return empty UniversalOptions]
D -- no --> F[Parse scheme / host / path / query]
F --> G{scheme rediss?}
G -- yes --> H[Set TLSConfig MinTLS1.2]
G -- no --> I[No TLS from URL]
F --> J[Parse query params client_name db addrs sentinel_* pool_* timeouts...]
H --> K[opts returned to newUniversalOptions]
I --> K
J --> K
E --> K
K --> L{cfg.Addr set?}
L -- yes --> M[opts.Addrs = addr]
L -- no --> N{cfg.Addrs set?}
N -- yes --> O[opts.Addrs = addrs]
N -- no --> P{opts.Addrs empty?}
P -- yes --> Q[ERROR: addr required]
P -- no --> R[Continue]
M --> N
O --> R
R --> S[Override Username Password MasterName SentinelUsername/Password RouteByLatency RouteRandomly IsClusterMode DB]
S --> T{cfg.TLS?}
T -- yes --> U[Create/update TLSConfig Apply InsecureSkipVerify]
T -- no --> V{cfg.TLSInsecureSkipVerify without TLSConfig?}
U --> W[return opts]
V -- yes --> X[ERROR: TLS required]
V -- no --> W
W --> Y[redis.NewUniversalClient opts]
Y --> Z{opts.MasterName set?}
Z -- yes --> ZA{opts.IsClusterMode?}
ZA -- yes --> ZB[FailoverClusterClient]
ZA -- no --> ZC[FailoverClient Sentinel]
Z -- no --> ZD{IsClusterMode or len Addrs gt 1?}
ZD -- yes --> ZE[ClusterClient]
ZD -- no --> ZF[standalone Client]
Reviews (3): Last reviewed commit: "fix: remove deletion of query parameters..." | Re-trigger Greptile |
| func (o *queryOptions) string(name string) string { | ||
| vs := o.q[name] | ||
| if len(vs) == 0 { | ||
| return "" | ||
| } | ||
| delete(o.q, name) // enable detection of unknown parameters | ||
| return vs[len(vs)-1] | ||
| } |
There was a problem hiding this comment.
Unknown URL query parameters silently swallowed
The string() method calls delete(o.q, name) with the comment "enable detection of unknown parameters", implying that after all known parameters are consumed any remaining keys in o.q should surface as errors. However, there is no code that checks len(o.q) > 0 after parsing completes. A user who types pool_sise=50 (typo) or any unrecognised key will get no warning, and their configuration will be silently ignored.
There was a problem hiding this comment.
避免存在歧义,已把delete删除
…lone, sentinel, and cluster modes
…s for better parameter handling
* feat: update Redis configuration to support multiple mode(use UniversalClient) * fix: update parameter names in ParseUniversalURL for consistency * feat: enhance Redis configuration to support standalone, sentinel, and cluster modes * fix: improve error wrapping for invalid number in queryOptions * fix: correct parameter name from 'addr' to 'addrs' in Redis configuration * feat: add support for configuring Redis parameters via URL for standalone, sentinel, and cluster modes * fix: remove deletion of query parameters in string and strings methods for better parameter handling
需求背景
当前 AxonHub 仅支持单机模式的 Redis 连接,该架构存在明显的单点故障风险。
主要修改
业务价值