feat(redis): add Redis Cluster client support to plugin-daemon#701
Draft
feat(redis): add Redis Cluster client support to plugin-daemon#701
Conversation
Wire the missing third branch so operators can point the daemon at a Redis Cluster without falling back to dialing an empty REDIS_HOST:PORT and panicking at startup. * introduce REDIS_USE_CLUSTERS / REDIS_CLUSTERS / REDIS_CLUSTERS_PASSWORD envs, aligned with dify api naming so Helm can set a single env group * branch in PluginManager.Launch for Cluster ahead of the existing Sentinel / standalone paths; falls back to REDIS_PASSWORD if the cluster-specific password is not set * implement cache.InitRedisClusterClient via redis.NewClusterClient; downstream cache / lock / pub-sub helpers keep working because `client` is declared as redis.UniversalClient Redis Cluster disables SELECT DB, so the cluster branch does not plumb RedisDB. This is intentional and documented in the release note accompanying the overall Redis Cluster support work. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds Redis Cluster support, including new configuration fields and the InitRedisClusterClient utility. The PluginManager now supports cluster initialization. Key feedback highlights that the current Transaction() implementation is incompatible with Redis Cluster, suggests generalizing error messages in utility functions, and recommends refactoring redundant TLS configuration logic.
Comment on lines
+119
to
+127
| if useSsl { | ||
| if tlsConf != nil { | ||
| opts.TLSConfig = tlsConf | ||
| } else { | ||
| opts.TLSConfig = &tls.Config{ | ||
| MinVersion: tls.VersionTLS12, | ||
| } | ||
| } | ||
| } |
Contributor
Narrow the plugin-daemon Redis client to standalone and sentinel modes; remove the cluster code paths that were briefly exercised on this branch. Changes: - Remove REDIS_USE_CLUSTERS / REDIS_CLUSTERS / REDIS_CLUSTERS_PASSWORD env fields from app.Config. - Remove the cluster branch (plus the two cluster-specific fail-fast guards on REDIS_USE_CLUSTERS + REDIS_USE_SENTINEL and REDIS_DB != 0) from PluginManager.Launch. The init block is now just sentinel or standalone. - Delete cache.InitRedisClusterClient. The main redis client + all helpers (Transaction, pub/sub, lock, etc.) already route through redis.UniversalClient so downstream code needs no adjustment. Intentionally kept: - Transaction(fn, watchKeys...) signature: the variadic signature is backwards-compatible with every existing Transaction(fn) call and the one new-style caller (debugging_service) benefits from real WATCH semantics even on standalone — this is correctness-independent of cluster support. - parser.SplitAndTrimCSV: the sentinel branch migrated to it in 617e7a5 and still uses it to parse REDIS_SENTINELS, so the helper has a standalone/sentinel consumer and stays. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
背景
目前
plugin-daemon的 Redis 初始化只支持 单机 (Single) 和 哨兵 (Sentinel) 两种模式。在使用 Redis Cluster 部署的环境中,用户无法直接接入,需要额外的代理或降级方案。本 PR 补齐 Cluster 模式,让三种拓扑在部署侧完全对齐。变更内容
新增集群初始化入口 pkg/utils/cache/redis.go
InitRedisClusterClient(addrs, username, password, useSsl, tlsConf),基于redis.NewClusterClient构建,与现有Single/Sentinel路径共享同一个redis.UniversalClient抽象,下游无感知。redisoteltracing 注入与Ping健康检查。addrs为空的情况返回显式错误,避免配置遗漏时静默失败。新增配置项 internal/types/app/config.go
REDIS_USE_CLUSTERS(bool, 默认false):Cluster 模式总开关。REDIS_CLUSTERS(string):以英文逗号分隔的host:port列表。REDIS_CLUSTERS_PASSWORD(string, 可选):Cluster 专用密码;未设置时回退到REDIS_PASSWORD,方便复用既有凭据。接入启动流程 internal/core/plugin_manager/manager.go
PluginManager.Launch的 Redis 初始化加入 Cluster 分支,优先级:Clusters→Sentinel→Single。splitAndTrimCSV小工具对REDIS_CLUSTERS做切分与空值/空白过滤,容忍"a, b, ,c"这类不规整配置。兼容性
REDIS_USE_CLUSTERS=false,所有现有部署零改动、零行为变化。使用方式
测试计划