feat: add duplicate() method to RedisSentinel#3212
Conversation
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
|
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. |
|
@claygeo thanks, i will have a look |
|
@claygeo hi again, sorry for the delay!
That is not true. Sentinel supports pubsub out of the box. It creates and maintains a new background connection via the I do agree that we should add the method for consistency though. |

Problem
RedisClientTypeandRedisClusterTypeboth expose aduplicate()method for creating a new connection with the same configuration (plus optional overrides).RedisSentinelTypeis 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:
Solution
Add
duplicate()to theRedisSentinelclass following the exact same pattern used byRedisClient(client/index.ts:1028) andRedisCluster(cluster/index.ts):The duplicated instance is not connected. Users call
.connect()on it, same as withRedisClient.duplicate().Changes
packages/client/lib/sentinel/index.ts-- Addedduplicate()method toRedisSentinelclassBackwards Compatibility
Additive only. No existing methods or types are changed.
Closes #3107
Note
Low Risk
Low risk additive change that mirrors existing
duplicate()implementations onRedisClient/RedisClusterand does not alter connection or command execution paths.Overview
Adds
RedisSentinel.duplicate()to instantiate a new sentinel client using the current instance’s stored#optionsand#commandOptions, with optional overrides, matching theduplicate()behavior already available onRedisClientandRedisCluster.Written by Cursor Bugbot for commit 1135895. This will update automatically on new commits. Configure here.