feat(redis): keep services running when Redis is unreachable

Add a lazy Redis client constructor and an in-memory fallback for the
refresh-session store, plus tenant-api and ops-api bootstrap that warns
and continues with the lazy client instead of failing. Refresh and
blacklist operations now silently fall back to the in-memory store while
Redis is down so existing sessions stay valid until it recovers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-30 01:06:08 +08:00
parent 2aa39d7a11
commit 11bd4e4d4e
5 changed files with 183 additions and 17 deletions
+3 -1
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"github.com/geo-platform/tenant-api/internal/ops/app"
opsconfig "github.com/geo-platform/tenant-api/internal/ops/config"
@@ -54,7 +55,8 @@ func main() {
rdb, err := redis.NewClient(ctx, cfg.Redis)
if err != nil {
logger.Sugar().Fatalf("ops-api init redis: %v", err)
logger.Warn("redis unavailable during startup; continuing with degraded auth/cache fallback", zap.Error(err))
rdb = redis.NewLazyClient(cfg.Redis)
}
defer func() { _ = rdb.Close() }()
appCache := cache.New(cfg.Cache.Driver, rdb)