package app import ( "context" "errors" "galaxy/redisconn" "galaxy/gamemaster/internal/config" "galaxy/gamemaster/internal/telemetry" "github.com/redis/go-redis/v9" ) // newRedisClient builds the master Redis client from cfg via the shared // `pkg/redisconn` helper. Replica clients are not opened in this iteration // per ARCHITECTURE.md §Persistence Backends; they will be wired when read // routing is introduced. func newRedisClient(cfg config.RedisConfig) *redis.Client { return redisconn.NewMasterClient(cfg.Conn) } // instrumentRedisClient attaches the OpenTelemetry tracing and metrics // instrumentation to client when telemetryRuntime is available. The // actual instrumentation lives in `pkg/redisconn` so every Galaxy service // shares one surface. func instrumentRedisClient(redisClient *redis.Client, telemetryRuntime *telemetry.Runtime) error { if redisClient == nil { return errors.New("instrument redis client: nil client") } if telemetryRuntime == nil { return nil } return redisconn.Instrument(redisClient, redisconn.WithTracerProvider(telemetryRuntime.TracerProvider()), redisconn.WithMeterProvider(telemetryRuntime.MeterProvider()), ) } // pingRedis performs a single Redis PING bounded by // cfg.Conn.OperationTimeout to confirm that the configured Redis endpoint // is reachable at startup. func pingRedis(ctx context.Context, cfg config.RedisConfig, redisClient *redis.Client) error { return redisconn.Ping(ctx, redisClient, cfg.Conn.OperationTimeout) }