Skip to content

fix(sentinel): propagate RESP option to clients #3011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/client/lib/sentinel/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('RedisSentinel', () => {
{ host: 'localhost', port: 26379 }
]
};

it('should throw error when clientSideCache is enabled with RESP 2', () => {
assert.throws(
() => RedisSentinel.create({
Expand All @@ -46,14 +46,24 @@ describe('RedisSentinel', () => {
});

it('should not throw when clientSideCache is enabled with RESP 3', () => {
assert.doesNotThrow(() =>
assert.doesNotThrow(() =>
RedisSentinel.create({
...options,
clientSideCache: clientSideCacheConfig,
RESP: 3 as const,
})
);
});

testUtils.testWithClientSentinel('should successfully connect to sentinel', async () => {
}, {
...GLOBAL.SENTINEL.OPEN,
sentinelOptions: {
RESP: 3,
clientSideCache: { ttl: 0, maxEntries: 0, evictPolicy: 'LRU'},
},
})

});
});
});
Expand Down Expand Up @@ -417,7 +427,7 @@ async function steadyState(frame: SentinelFramework) {
sentinel.setTracer(tracer);
await sentinel.connect();
await nodePromise;

await sentinel.flushAll();
} finally {
if (sentinel !== undefined) {
Expand All @@ -443,7 +453,7 @@ describe('legacy tests', () => {
this.timeout(15000);

last = Date.now();

function deltaMeasurer() {
const delta = Date.now() - last;
if (delta > longestDelta) {
Expand Down Expand Up @@ -508,7 +518,7 @@ describe('legacy tests', () => {
}

stopMeasuringBlocking = true;

await frame.cleanup();
})

Expand Down Expand Up @@ -1032,6 +1042,3 @@ describe('legacy tests', () => {
})
});
});



5 changes: 5 additions & 0 deletions packages/client/lib/sentinel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ class RedisSentinelInternal<
readonly #sentinelClientOptions: RedisClientOptions<typeof RedisSentinelModule, RedisFunctions, RedisScripts, RespVersions, TypeMapping, RedisTcpSocketOptions>;
readonly #scanInterval: number;
readonly #passthroughClientErrorEvents: boolean;
readonly #RESP?: RespVersions;

#anotherReset = false;

Expand Down Expand Up @@ -673,6 +674,7 @@ class RedisSentinelInternal<

this.#name = options.name;

this.#RESP = options.RESP;
this.#sentinelRootNodes = Array.from(options.sentinelRootNodes);
this.#maxCommandRediscovers = options.maxCommandRediscovers ?? 16;
this.#masterPoolSize = options.masterPoolSize ?? 1;
Expand Down Expand Up @@ -716,6 +718,9 @@ class RedisSentinelInternal<

#createClient(node: RedisNode, clientOptions: RedisClientOptions, reconnectStrategy?: undefined | false) {
return RedisClient.create({
//first take the globally set RESP
RESP: this.#RESP,
//then take the client options, which can in theory overwrite it
...clientOptions,
socket: {
...clientOptions.socket,
Expand Down
2 changes: 2 additions & 0 deletions packages/test-utils/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export default class TestUtils {
port: promise.port
}));


const sentinel = createSentinel({
name: 'mymaster',
sentinelRootNodes: rootNodes,
Expand All @@ -352,6 +353,7 @@ export default class TestUtils {
functions: options?.functions || {},
masterPoolSize: options?.masterPoolSize || undefined,
reserveClient: options?.reserveClient || false,
...options?.sentinelOptions
}) as RedisSentinelType<M, F, S, RESP, TYPE_MAPPING>;

if (options.disableClientSetup) {
Expand Down
Loading