Skip to content

docs: explain how to share a client between modules - #3527

Merged
nkaradzhov merged 2 commits into
redis:masterfrom
smit153:docs/1794-shared-client
Oct 22, 2026
Merged

nkaradzhov merged 2 commits into
redis:masterfrom
smit153:docs/1794-shared-client

Conversation

@smit153

@smit153 smit153 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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 --check passed.


Checklist

  • Does npm test pass with this change (including linting)? Full suite not run; documentation-only change.
  • Is the new or changed code fully tested? Executed the documentation snippets and checked connection reuse and shutdown.
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? FAQ updated; no API changes.

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 call close() only at application shutdown.

The new text also covers top-level await (connection readiness and import failure if connect() rejects), a warning that the default reconnect strategy can block startup indefinitely when Redis is down, and a pointer to reconnectStrategy for fail-fast behavior. A small markdown fix closes the RedisClientType code fence correctly.

Reviewed by Cursor Bugbot for commit 86e85b4. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T18:10:11.485196Z 3e15d65 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@smit153

smit153 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@nkaradzhov Thanks for the review! Added the clarification about indefinite startup retries and linked to reconnectStrategy for applications that should fail fast. Updated in 86e85b4.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nkaradzhov
nkaradzhov merged commit 1fd0e5f into redis:master Oct 22, 2026
4 checks passed
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.

Documentation missing for exporting connection from one module and using it from other module

2 participants