feat: support passing existing Redis client to ISR handler#31
feat: support passing existing Redis client to ISR handler#31mrjasonroy wants to merge 1 commit intomainfrom
Conversation
Allows RedisCacheHandler to accept a pre-existing ioredis client instance, enabling connection reuse and custom configurations (Cluster, Sentinel, etc.). Key changes: - Accept Redis instance via duck typing (avoids instanceof fragility) - Track didCreateClient to skip error listeners for shared clients - close() only disconnects internally-created clients - Added 5 tests for existing client behavior Based on #23 by @Antignote with improvements to the detection mechanism and lifecycle management. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @mrjasonroy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature by allowing an existing Redis client instance to be passed to the RedisCacheHandler. The implementation correctly uses duck typing to detect the client and manages the client's lifecycle (error listeners, closing connection) based on whether it was created internally or provided externally. The accompanying tests are comprehensive and validate the new behavior thoroughly. I have one suggestion to improve the robustness of the duck-typing check.
| options.redis && | ||
| typeof options.redis === "object" && | ||
| "get" in options.redis && | ||
| "set" in options.redis && | ||
| "del" in options.redis && | ||
| typeof (options.redis as Redis).get === "function" |
There was a problem hiding this comment.
The current duck-typing for an existing Redis client is not fully robust. It checks for the existence of get, set, and del properties, but only confirms that get is a function. This could lead to runtime errors if an object is passed where set or del are properties but not functions.
A more robust approach is to verify that all three methods (get, set, del) are indeed functions. This also simplifies the condition by making the in checks redundant.
options.redis &&
typeof options.redis === "object" &&
typeof (options.redis as Redis).get === "function" &&
typeof (options.redis as Redis).set === "function" &&
typeof (options.redis as Redis).del === "function"|
Closing in favor of pushing updates directly to #23 |
Summary
RedisCacheHandlerto accept a pre-existing ioredis client instance via theredisoptioninstanceof Redisto detect existing clients (avoids fragility across package versions/bundlers)didCreateClientto skip error listeners andclose()for shared clientsBased on #23 by @Antignote, reworked to address review feedback:
instanceof Rediswith duck typingdidCreateClientconsistently for both error listener and closeSupersedes #23
Test plan
🤖 Generated with Claude Code