Skip to content

feat: add duplicate() method to RedisSentinel#3212

Open
claygeo wants to merge 2 commits intoredis:masterfrom
claygeo:fix/sentinel-duplicate-method
Open

feat: add duplicate() method to RedisSentinel#3212
claygeo wants to merge 2 commits intoredis:masterfrom
claygeo:fix/sentinel-duplicate-method

Conversation

@claygeo
Copy link
Copy Markdown

@claygeo claygeo commented Mar 27, 2026

Problem

RedisClientType and RedisClusterType both expose a duplicate() method for creating a new connection with the same configuration (plus optional overrides). RedisSentinelType is missing this method, forcing users to manually reconstruct the full sentinel configuration when they need a second connection.

Common use case: pub/sub requires a dedicated connection, so users need to duplicate their sentinel connection:

const sentinel = createSentinel({ ... }).on('error', console.error);
await sentinel.connect();

// Currently impossible:
const subscriber = sentinel.duplicate();

// Users must manually reconstruct:
const subscriber = createSentinel({ ...sameConfigAgain }).on('error', console.error);

Solution

Add duplicate() to the RedisSentinel class following the exact same pattern used by RedisClient (client/index.ts:1028) and RedisCluster (cluster/index.ts):

duplicate<...>(overrides?) {
  return new (Object.getPrototypeOf(this).constructor)({
    ...this._self.#options,
    commandOptions: this._commandOptions,
    ...overrides
  }) as RedisSentinelType<...>;
}

The duplicated instance is not connected. Users call .connect() on it, same as with RedisClient.duplicate().

Changes

  • packages/client/lib/sentinel/index.ts -- Added duplicate() method to RedisSentinel class

Backwards Compatibility

Additive only. No existing methods or types are changed.

Closes #3107


Note

Low Risk
Low risk additive change that mirrors existing duplicate() implementations on RedisClient/RedisCluster and does not alter connection or command execution paths.

Overview
Adds RedisSentinel.duplicate() to instantiate a new sentinel client using the current instance’s stored #options and #commandOptions, with optional overrides, matching the duplicate() behavior already available on RedisClient and RedisCluster.

Written by Cursor Bugbot for commit 1135895. This will update automatically on new commits. Configure here.

RedisClient and RedisCluster both expose a duplicate() method that
creates a new instance with the same options (plus optional
overrides). RedisSentinel is missing this method, which forces
users to manually reconstruct the sentinel configuration when they
need a second connection (e.g., for pub/sub alongside regular
commands).

Adds duplicate() to the RedisSentinel class following the exact
same pattern used by RedisClient and RedisCluster:
- Creates a new instance via Object.getPrototypeOf(this).constructor
- Spreads existing options + commandOptions + overrides
- Returns the correctly typed RedisSentinelType

Closes redis#3107
@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Mar 27, 2026

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.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

duplicate() is missing on RedisSentinelType

1 participant