feat(cluster): support custom Redis class for internal connections#2097
feat(cluster): support custom Redis class for internal connections#2097rit3sh-x wants to merge 3 commits into
Conversation
Adds a new 'redisClass' option to ClusterOptions that lets users pass a Redis subclass to be used for every internal connection the Cluster creates: pool nodes, pub/sub subscriber, sharded subscribers, and slot refresh connections. This enables instrumentation, logging, OpenTelemetry tracing, and custom error handling for Cluster without monkeypatching. Closes redis#2073
|
Thanks for the PR. I will review it and follow up once I have gone through it. |
|
run sharded pub sub tests |
|
1 similar comment
|
|
|
@uglide thanks for running this. I can't access the CAE action logs from outside, could you share the failure output for the two Failure Recovery cases (Multiple Subscribers / Single Subscriber)? I want to confirm whether this is a regression from threading |
|
@PavelPashov @uglide quick update on the CAE Failure Recovery failures. I spun up a local branch ( What I tested, against both a local Redis cluster and a single-node instance: On
On
So the local functional suite passes on both branches, which means the CAE Failure Recovery cases are exercising a code path my local tests do not cover. I cannot reproduce the CAE harness locally, so I cannot directly confirm the hypothesis from my side. |
|
@PavelPashov any updates? |
Summary
Closes #2073.
Adds a
redisClassoption toClusterOptionsso users can pass a Redis subclass (e.g.class RedisWithInstrumentation extends Redis) and have it used for every internal connection theCluster creates.
Motivation
Users who subclass Redis for OpenTelemetry, logging, or custom error handling currently can't use their subclass with Cluster, because Cluster hardcodes
new Redis(...)internally in multipleplaces (pool, subscribers, slot refresher). This forces monkeypatching.
What changes
redisClassis threaded fromClusterOptionsto every internal Redis construction site:ConnectionPool— pool node connectionsClusterSubscriber— pub/sub subscriberShardedSubscriber(viaClusterSubscriberGroup) — sharded pub/sub subscribersCluster.getInfoFromNode— slot refresh connections (previously usedredis.duplicate())Defaults to
Rediswhen not set — zero breaking changes.Usage
Test plan
New test file
test/functional/cluster/redis_class.tswith 8 behavior-focused tests:sendCommandoverride actually intercepts commands end-to-endFull suite: 562 passing, 17 cluster passing, build + tsd pass.
Notes
duplicate()). That's a separate issue rooted in the Commander mixin system and warrants its own PR.Note
Medium Risk
Touches core Cluster connection creation paths (pool nodes, subscribers, and slot-refresh connections), so regressions could affect connectivity and slot refresh behavior despite being opt-in. Backward compatibility is preserved by defaulting to
Redis, and functional tests cover the new wiring.Overview
Adds a new
ClusterOptions.redisClasshook so a user-providedRedissubclass is used for all internal Cluster connections (node pool, subscriber, sharded subscribers, and slot refresh).Threads
redisClassthroughConnectionPool,ClusterSubscriber,ShardedSubscriber/ClusterSubscriberGroup, and changes slot refresh to create a new connection viaredisClass(instead ofredis.duplicate()), then adds functional tests asserting default behavior and that instrumentation/overrides (e.g.sendCommand) apply end-to-end.Reviewed by Cursor Bugbot for commit a51dd8c. Bugbot is set up for automated code reviews on this repo. Configure here.