11bd4e4d4e
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>
28 lines
551 B
Go
28 lines
551 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
goredis "github.com/redis/go-redis/v9"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/config"
|
|
)
|
|
|
|
func NewClient(ctx context.Context, cfg config.RedisConfig) (*goredis.Client, error) {
|
|
client := NewLazyClient(cfg)
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
return nil, fmt.Errorf("ping redis: %w", err)
|
|
}
|
|
|
|
return client, nil
|
|
}
|
|
|
|
func NewLazyClient(cfg config.RedisConfig) *goredis.Client {
|
|
client := goredis.NewClient(&goredis.Options{
|
|
Addr: cfg.Addr,
|
|
DB: cfg.DB,
|
|
})
|
|
return client
|
|
}
|