fix: Redis 连接支持集群/哨兵模式自适配 (#89)#115
Draft
ljluestc wants to merge 5 commits intoxinliangnote:masterfrom
Draft
Conversation
使用 redis.UniversalClient 替代 *redis.Client,根据配置自动适配单机/集群/哨兵模式。 - 配置层新增 addrs 和 masterName 字段,保留 addr 向后兼容 - 提取 options 子包封装 BuildUniversalOptions 适配逻辑 - 安装向导支持逗号分隔的多地址输入 - 新增 5 个单元测试覆盖各模式
c7b4594 to
d30ddaa
Compare
- Removed Oz co-author references - Added comprehensive step-by-step implementation guide - Included HTTP and WebSocket proxy code examples - Added local testing procedures and performance benchmarks
Add comprehensive reverse proxy functionality: - HTTPProxier using Go's httputil.ReverseProxy - WebSocketProxier with bidirectional message relay - Proxy handler supporting both protocols - Router integration with proxy routes - Test script for local validation This resolves issue xinliangnote#91 by enabling native proxy support for both HTTP and WebSocket connections.
62057d4 to
4f5a1e9
Compare
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.
fix: Redis 连接支持集群/哨兵模式自适配 (Closes #89)
问题描述
当前项目 Redis 连接方式硬编码使用 redis.NewClient(单机模式),无法支持 Redis Cluster 或 Sentinel 部署。用户需要手动改造代码才能适配不同的 Redis 部署模式。
解决方案
使用 go-redis/v7 提供的 redis.UniversalClient 接口替代 *redis.Client,通过 redis.NewUniversalClient 根据配置自动选择连接模式:
• 单地址 (addr) → 单机模式(向后兼容,无需修改现有配置)
• 多地址 (addrs) → 集群模式(Redis Cluster)
• 多地址 + masterName → 哨兵模式(Redis Sentinel)
改动文件
configs/configs.go — Redis 配置新增 Addrs []string 和 MasterName string 字段,保留 Addr 向后兼容
configs/fat_configs.toml — 新增 addrs 和 masterName 配置项
internal/repository/redis/options/options.go — 新增子包,包含 RedisConfig 结构体和 BuildUniversalOptions() 核心适配逻辑
internal/repository/redis/redis.go — cacheRepo.client 从 *redis.Client 改为 redis.UniversalClient,redisConnect() 调用 options.BuildUniversalOptions() 后使用 redis.NewUniversalClient
internal/render/install/execute.go — 安装向导支持逗号分隔的多地址输入,验证改用 redis.NewUniversalClient
internal/repository/redis/options/options_test.go — 5 个测试用例覆盖单机/集群/哨兵/优先级/空配置