Skip to content

feat(redis): connect to Redis at startup with shared client - #58

Open
diangogav wants to merge 1 commit into
mainfrom
feat/redis-startup-connection
Open

feat(redis): connect to Redis at startup with shared client#58
diangogav wants to merge 1 commit into
mainfrom
feat/redis-startup-connection

Conversation

@diangogav

Copy link
Copy Markdown
Owner

What

Connect to Redis during the boot sequence and log successful connections to both Postgres datasources and Redis.

Why

Bun's `RedisClient` connects lazily — on the first command. Before this change the Redis client was instantiated inside `ticket-router.ts` but never connected at startup, so a misconfigured or down Redis would only surface on the first `POST /game-tickets` request, not at boot.

Changes

  • `src/shared/redis/redisClient.ts` (new): extract the Redis client to a shared module-level singleton, consistent with how the Postgres datasources are wired. This ensures the startup check validates the same connection the ticket repository uses.
  • `src/index.ts`: `await redisClient.connect()` in the boot sequence, following the existing Postgres pattern. Success logs added for both Postgres schemas and Redis via `.then()` (so the "Connected" log only prints on actual success, not when `.catch` swallows an error).
  • `src/server/routes/ticket-router.ts`: reuse the shared client instead of creating its own.

Notes

Keeps the existing log-and-continue error semantics (matches Postgres): a connection failure is logged but does not abort the process. This is detection-early, not strict fail-fast, intentionally consistent with the rest of the boot.

Extract the Redis client to a shared singleton and connect it during the
boot sequence so connectivity is validated (and logged) at startup instead
of lazily on first request. Add success logs for both Postgres datasources
and Redis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant