Repository navigation
docs: explain how to share a client between modules - #3527
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
nkaradzhov
left a comment
There was a problem hiding this comment.
Thanks — this FAQ entry is a good fit for #1794.
One change before merge: with the default reconnectStrategy, an unreachable Redis does not make connect() reject — the client keeps retrying, so the top-level await (and every importing module) waits indefinitely. Please add a sentence saying so, with a link to reconnectStrategy for apps that should fail fast at startup.
|
@nkaradzhov Thanks for the review! Added the clarification about indefinite startup retries and linked to |
Description
The FAQ shows how to export a client for typing, but does not explain how to connect it and reuse it from another module.
Add a complete ES module example showing connection initialization, importing the shared client, and closing it when the application finishes. Explain how top-level await makes the connection ready before use and why consumers should not close it after each operation.
Closes #1794.
Validation
Ran the documented snippets on Node.js 22 against Redis 8. Verified the expected set/get result, the same Redis connection ID from a separate consumer module, and clean process exit after
close().git diff --checkpassed.Checklist
npm testpass with this change (including linting)? Full suite not run; documentation-only change.Note
Low Risk
Documentation-only FAQ update with no runtime or API changes.
Overview
Adds a new FAQ entry “How do I share a client between modules?” that documents the recommended ES module pattern: create and
connect()in one file, import the same exported client elsewhere, and callclose()only at application shutdown.The new text also covers top-level
await(connection readiness and import failure ifconnect()rejects), a warning that the default reconnect strategy can block startup indefinitely when Redis is down, and a pointer toreconnectStrategyfor fail-fast behavior. A small markdown fix closes theRedisClientTypecode fence correctly.Reviewed by Cursor Bugbot for commit 86e85b4. Bugbot is set up for automated code reviews on this repo. Configure here.