Repository navigation
Conversation
The redis option only took RedisOptions, so the plugin always created and owned its connection. Callers who want to manage the connection themselves (e.g. attach their own 'error' handling, or share one client across the app) had no way to pass it in. The option now also accepts a Redis URL string and an ioredis Redis client. A provided client is used as-is: the plugin never quits it and adds no 'error' listener to it. The pub/sub connections the message broker derives from it with duplicate() are still owned and closed by the plugin. A client is detected with instanceof, falling back to a method-shape check so clients from another copy of ioredis are recognised too. Fixes #59 Co-authored-by: David Wood <david.p.wood@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
redisoption only acceptedRedisOptions, so the plugin always created and owned its Redis connection. Users who want to manage the connection themselves (their ownerrorhandling, connect/retry policy, or one client shared across the app) could not pass it in.redisnow accepts any of:Redisclient: used as-is. The plugin never quits it and adds noerrorlistener to it; the caller owns it. The message broker's pub/sub connections are derived from it withduplicate(), and the plugin closes those onapp.close().redis://localhost:6379/0: the plugin creates and closes the client.RedisOptions: unchanged.A client is detected with
instanceof Redis, falling back to a method-shape check (duplicate,quit,disconnect,on,get,hset), so clients from a different copy of ioredis are recognised too (src/redis-client.ts).Changes
src/index.ts: picks the client from the option and only quits a connection the plugin created.src/types.ts:redis?: Redis | RedisOptions | string.test/redis-client-option.test.ts: a provided client is used (session lands in Redis), staysreadyafterapp.close(), gets no leftover listeners, and itsduplicate()d connections end up closed. Also covers URL and options forms, plus the detection helper.test-d/index.test-d.ts: type tests for the client and URL forms.onClosehooks run in reverse order, which matters if you quit your client from one.Not breaking: existing
RedisOptionsconfigurations behave exactly as before.Fixes #59
Supersedes #60
Thanks to @Codesleuth (David Wood) for the original implementation in #60. This PR takes the same approach, rewritten against current main after the
redisoption was retyped in #287. David is credited as co-author on the commit.🤖 Generated with Claude Code
https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM