关于上游流量同步覆盖修复,以及新增redis同步迁移
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m25s

This commit is contained in:
Break
2026-05-27 10:59:19 +08:00
parent cf689beceb
commit 0d96a94e5f
6 changed files with 349 additions and 6 deletions

View File

@@ -45,6 +45,16 @@ func NewPollingConfigManager(configStore *postgres.PollingConfigStore, redisClie
// Load 加载配置到内存缓存并同步到 Redis
// 加载失败时保留原缓存不清空,确保可用性
func (m *PollingConfigManager) Load(ctx context.Context) error {
return m.load(ctx, true)
}
// LoadForInspection 加载配置到内存缓存但不同步 Redis。
// 用于迁移 dry-run 等只读检查场景,避免检查动作产生外部副作用。
func (m *PollingConfigManager) LoadForInspection(ctx context.Context) error {
return m.load(ctx, false)
}
func (m *PollingConfigManager) load(ctx context.Context, syncRedis bool) error {
configs, err := m.configStore.ListEnabled(ctx)
if err != nil {
m.logger.Error("加载轮询配置失败", zap.Error(err))
@@ -55,8 +65,12 @@ func (m *PollingConfigManager) Load(ctx context.Context) error {
m.configs = configs
m.mu.Unlock()
if syncErr := m.syncToRedis(ctx, configs); syncErr != nil {
m.logger.Warn("同步配置到 Redis 失败", zap.Error(syncErr))
if syncRedis && m.redis != nil {
if syncErr := m.syncToRedis(ctx, configs); syncErr != nil {
m.logger.Warn("同步配置到 Redis 失败", zap.Error(syncErr))
}
} else if syncRedis {
m.logger.Warn("Redis 客户端为空,跳过轮询配置同步")
}
m.logger.Info("轮询配置已加载", zap.Int("count", len(configs)))