feat(client): expose RedisClient, RedisCluster, RedisSentinel and pool classes#3251
Merged
Merged
Conversation
…l classes Re-export the underlying classes (previously only accessible as default exports on internal paths) alongside the existing factory functions, so consumers can use `instanceof` checks and stub methods on the prototype without reaching into `@redis/client/dist/...`. Also exposes `RedisClientPool`, `RedisSentinelClient` and the `RedisSentinelClientType` type. The factories (`createClient`, `createCluster`, `createSentinel`, `createClientPool`) remain unchanged, so existing code keeps working. Note: command methods (get, set, etc.) are attached to a dynamic subclass produced by the `factory()` call per config, not to `RedisClient.prototype` itself. `instanceof RedisClient` still works (prototype chain: proxy -> subclass instance -> subclass.prototype -> RedisClient.prototype), and methods defined directly on the base class (connect, quit, _executeCommand, EventEmitter methods) can be stubbed via the prototype; command-level stubs still need to target the instance or `_executeCommand`.
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
Collaborator
|
@aarond-sp thanks, this looks good! |
nkaradzhov
approved these changes
Apr 23, 2026
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.
Description
Expose the underlying
RedisClient,RedisCluster,RedisSentinel,RedisSentinelClientandRedisClientPoolclasses (plus theRedisSentinelClientTypetype) as named exports from@redis/client. Today only the factory functions (createClient,createCluster,createSentinel,createClientPool) are exported, which forces consumers reaching forinstanceofchecks or prototype-level stubbing in tests to import from internal paths like@redis/client/dist/lib/client— fragile, and not covered by the public API contract.Why
instanceofchecks: frameworks, DI containers and user code frequently wantx instanceof RedisClient/instanceof RedisSentinel. This already works at runtime (the factory returns anObject.create(new Subclass(...))whose prototype chain terminates atRedisClient.prototype) — it just wasn't reachable via the public API.RedisClient.prototype.<method>work for methods defined directly on the base class (connect,quit,_executeCommand,EventEmittermethods).Caveat worth flagging
Command methods (
get,set,hGet, …) are not onRedisClient.prototype. They are attached to a dynamic subclass produced per config byRedisClient.factory()viaattachConfig()and cached in aSingleEntryCache. That subclass isn't exported. Implications:instanceof RedisClient— ✅ works (prototype chain: proxy → subclass instance → subclass.prototype → RedisClient.prototype → EventEmitter.prototype).RedisClientitself (connect/quit/_executeCommand/EventEmitter) viaRedisClient.prototype.X = …— ✅ works.RedisClient.prototype.get = …— ❌ not found; command methods live on the subclass. For those, stub the instance or hook_executeCommandon the base prototype.Same applies to
RedisSentinelandRedisCluster(same factory pattern).Changes
packages/client/index.ts:RedisClient,RedisCluster,RedisSentinel,RedisSentinelClient,RedisClientPoolas named exports.RedisSentinelClientTypeto the existing type re-export from./lib/sentinel/types.Because
packages/redis/index.tsalready doesexport * from '@redis/client', these also propagate to the top-levelredispackage.Checklist
npm testpass with this change (including linting)? Build (tsc --build) is clean; existing test suite couldn't run locally due to an unrelated arm64 / Docker image availability issue forredislabs/client-libs-test— CI should exercise it on a supported platform.Note
Low Risk
Low risk: this is a strictly additive surface-area change that only re-exports existing classes/types, with no runtime logic changes. Main risk is minor API/typing impact from new named exports (e.g., potential name collisions for consumers).
Overview
Adds new public named exports from
@redis/client.packages/client/index.tsnow re-exports the underlyingRedisClient,RedisClientPool,RedisCluster,RedisSentinel, andRedisSentinelClientclasses (alongside existing factory functions).Also extends the Sentinel type exports to include
RedisSentinelClientType, and these new exports automatically propagate through the top-levelredispackage viaexport * from '@redis/client'.Reviewed by Cursor Bugbot for commit 6bb2277. Bugbot is set up for automated code reviews on this repo. Configure here.