Skip to content

Commit 08b6dac

Browse files
committed
feat(client): default connections to RESP3
- Switch default RESP behavior to RESP3 across client entry points. - Align cluster and sentinel command paths with RESP3 defaults. - Keep compatibility normalization and module fixes for later commits.
1 parent dbfe78d commit 08b6dac

35 files changed

Lines changed: 84 additions & 106 deletions

packages/bloom/lib/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const GLOBAL = {
1313
OPEN: {
1414
serverArguments: [],
1515
clientOptions: {
16+
RESP: 3 as const,
1617
modules: RedisBloomModules
1718
}
1819
}

packages/client/lib/RESP/types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ export type Command = {
292292
parseCommand(this: void, parser: CommandParser, ...args: Array<any>): void;
293293
TRANSFORM_LEGACY_REPLY?: boolean;
294294
transformReply: TransformReply | Record<RespVersions, TransformReply>;
295-
unstableResp3?: boolean;
296295
};
297296

298297
export type RedisCommands = Record<string, Command>;
@@ -321,18 +320,11 @@ export interface CommanderConfig<
321320
scripts?: S;
322321
/**
323322
* Specifies the Redis Serialization Protocol version to use.
324-
* RESP2 is the default (value 2), while RESP3 (value 3) provides
323+
* RESP3 is the default (value 3), while RESP2 (value 2) remains available for compatibility.
324+
* RESP3 provides
325325
* additional data types and features introduced in Redis 6.0.
326326
*/
327327
RESP?: RESP;
328-
/**
329-
* When set to true, enables commands that have unstable RESP3 implementations.
330-
* When using RESP3 protocol, commands marked as having unstable RESP3 support
331-
* will throw an error unless this flag is explicitly set to true.
332-
* This primarily affects modules like Redis Search where response formats
333-
* in RESP3 mode may change in future versions.
334-
*/
335-
unstableResp3?: boolean;
336328
}
337329

338330
type Resp2Array<T> = (

packages/client/lib/client/enterprise-maintenance-manager.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class EnterpriseMaintenanceManager {
8181
static setupDefaultMaintOptions(options: RedisClientOptions) {
8282
if (options.maintNotifications === undefined) {
8383
options.maintNotifications =
84-
options?.RESP === 3 ? "auto" : "disabled";
84+
(options?.RESP ?? 3) === 3 ? "auto" : "disabled";
8585
}
8686
if (options.maintEndpointType === undefined) {
8787
options.maintEndpointType = "auto";
@@ -123,14 +123,13 @@ export default class EnterpriseMaintenanceManager {
123123
errorHandler: (error: Error) => {
124124
dbgMaintenance("handshake failed:", error);
125125

126-
publish(CHANNELS.ERROR, () => ({
127-
error,
128-
origin: 'client',
129-
internal: true,
130-
clientId,
131-
}));
132-
133126
if (options.maintNotifications === "enabled") {
127+
publish(CHANNELS.ERROR, () => ({
128+
error,
129+
origin: 'client',
130+
internal: true,
131+
clientId,
132+
}));
134133
throw error;
135134
}
136135

packages/client/lib/client/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export type RedisClientExtensions<
235235
M extends RedisModules = {},
236236
F extends RedisFunctions = {},
237237
S extends RedisScripts = {},
238-
RESP extends RespVersions = 2,
238+
RESP extends RespVersions = 3,
239239
TYPE_MAPPING extends TypeMapping = {}
240240
> = (
241241
WithCommands<RESP, TYPE_MAPPING> &
@@ -248,7 +248,7 @@ export type RedisClientType<
248248
M extends RedisModules = {},
249249
F extends RedisFunctions = {},
250250
S extends RedisScripts = {},
251-
RESP extends RespVersions = 2,
251+
RESP extends RespVersions = 3,
252252
TYPE_MAPPING extends TypeMapping = {}
253253
> = (
254254
RedisClient<M, F, S, RESP, TYPE_MAPPING> &
@@ -326,7 +326,7 @@ export default class RedisClient<
326326
M extends RedisModules = {},
327327
F extends RedisFunctions = {},
328328
S extends RedisScripts = {},
329-
RESP extends RespVersions = 2
329+
RESP extends RespVersions = 3
330330
>(config?: CommanderConfig<M, F, S, RESP>) {
331331

332332

@@ -359,7 +359,7 @@ export default class RedisClient<
359359
M extends RedisModules = {},
360360
F extends RedisFunctions = {},
361361
S extends RedisScripts = {},
362-
RESP extends RespVersions = 2,
362+
RESP extends RespVersions = 3,
363363
TYPE_MAPPING extends TypeMapping = {}
364364
>(this: void, options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {
365365
return RedisClient.factory(options)(options);
@@ -628,16 +628,17 @@ export default class RedisClient<
628628
}
629629

630630
#validateOptions(options?: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>) {
631-
if (options?.clientSideCache && options?.RESP !== 3) {
631+
const resp = options?.RESP ?? 3;
632+
if (options?.clientSideCache && resp !== 3) {
632633
throw new Error('Client Side Caching is only supported with RESP3');
633634
}
634-
if (options?.emitInvalidate && options?.RESP !== 3) {
635+
if (options?.emitInvalidate && resp !== 3) {
635636
throw new Error('emitInvalidate is only supported with RESP3');
636637
}
637638
if (options?.clientSideCache && options?.emitInvalidate) {
638639
throw new Error('emitInvalidate is not supported (or necessary) when clientSideCache is enabled');
639640
}
640-
if (options?.maintNotifications && options?.maintNotifications !== 'disabled' && options?.RESP !== 3) {
641+
if (options?.maintNotifications && options?.maintNotifications !== 'disabled' && resp !== 3) {
641642
throw new Error('Graceful Maintenance is only supported with RESP3');
642643
}
643644
}
@@ -681,7 +682,7 @@ export default class RedisClient<
681682

682683
#initiateQueue(clientId: string): RedisCommandsQueue {
683684
return new RedisCommandsQueue(
684-
this.#options.RESP ?? 2,
685+
this.#options.RESP ?? 3,
685686
this.#options.commandsQueueMaxLength,
686687
(channel, listeners) => this.emit('sharded-channel-moved', channel, listeners),
687688
clientId
@@ -693,7 +694,7 @@ export default class RedisClient<
693694
*/
694695
private reAuthenticate = async (credentials: BasicAuth) => {
695696
// Re-authentication is not supported on RESP2 with PubSub active
696-
if (!(this.isPubSubActive && !this.#options.RESP)) {
697+
if (!(this.isPubSubActive && (this.#options.RESP ?? 3) === 2)) {
697698
await this.sendCommand(
698699
parseArgs(COMMANDS.AUTH, {
699700
username: credentials.username,
@@ -743,8 +744,9 @@ export default class RedisClient<
743744
> {
744745
const commands = [];
745746
const cp = this.#options.credentialsProvider;
747+
const resp = this.#options.RESP ?? 3;
746748

747-
if (this.#options.RESP) {
749+
if (resp !== 2) {
748750
const hello: HelloOptions = {};
749751

750752
if (cp && cp.type === 'async-credentials-provider') {
@@ -774,7 +776,7 @@ export default class RedisClient<
774776
hello.SETNAME = this.#options.name;
775777
}
776778

777-
commands.push({ cmd: parseArgs(HELLO, this.#options.RESP, hello) });
779+
commands.push({ cmd: parseArgs(HELLO, resp, hello) });
778780
} else {
779781
if (cp && cp.type === 'async-credentials-provider') {
780782
const credentials = await cp.credentials();

packages/client/lib/client/legacy-mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class RedisLegacyClient {
8181
) {
8282
this.#client = client;
8383

84-
const RESP = client.options?.RESP ?? 2;
84+
const RESP = client.options?.RESP ?? 3;
8585
for (const [name, command] of Object.entries(COMMANDS)) {
8686
// TODO: as any?
8787
(this as any)[name] = RedisLegacyClient.#createCommand(

packages/client/lib/client/multi-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default class RedisClientMultiCommand<REPLIES = []> {
176176
M extends RedisModules = Record<string, never>,
177177
F extends RedisFunctions = Record<string, never>,
178178
S extends RedisScripts = Record<string, never>,
179-
RESP extends RespVersions = 2
179+
RESP extends RespVersions = 3
180180
>(config?: CommanderConfig<M, F, S, RESP>) {
181181
return attachConfig({
182182
BaseClass: RedisClientMultiCommand,

packages/client/lib/client/pool.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ export interface RedisPoolOptions {
7070
* ```
7171
*/
7272
clientSideCache?: PooledClientSideCacheProvider | ClientSideCacheConfig;
73-
/**
74-
* Enable experimental support for RESP3 module commands.
75-
*
76-
* When enabled, allows the use of module commands that have been adapted
77-
* for the RESP3 protocol. This is an unstable feature and may change in
78-
* future versions.
79-
*
80-
* @default false
81-
*/
82-
unstableResp3Modules?: boolean;
8373
}
8474

8575
export type PoolTask<
@@ -103,7 +93,7 @@ export type RedisClientPoolType<
10393
M extends RedisModules = {},
10494
F extends RedisFunctions = {},
10595
S extends RedisScripts = {},
106-
RESP extends RespVersions = 2,
96+
RESP extends RespVersions = 3,
10797
TYPE_MAPPING extends TypeMapping = {}
10898
> = (
10999
RedisClientPool<M, F, S, RESP, TYPE_MAPPING> &
@@ -121,7 +111,7 @@ export class RedisClientPool<
121111
M extends RedisModules = {},
122112
F extends RedisFunctions = {},
123113
S extends RedisScripts = {},
124-
RESP extends RespVersions = 2,
114+
RESP extends RespVersions = 3,
125115
TYPE_MAPPING extends TypeMapping = {}
126116
> extends EventEmitter {
127117
static #createCommand(command: Command, resp: RespVersions) {

packages/client/lib/cluster/cluster-slots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class RedisClusterSlots<
127127
}
128128

129129
#validateOptions(options?: RedisClusterOptions<M, F, S, RESP, TYPE_MAPPING>) {
130-
if (options?.clientSideCache && options?.RESP !== 3) {
130+
if (options?.clientSideCache && (options?.RESP ?? 3) !== 3) {
131131
throw new Error('Client Side Caching is only supported with RESP3');
132132
}
133133
}

packages/client/lib/cluster/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export type RedisClusterType<
118118
M extends RedisModules = {},
119119
F extends RedisFunctions = {},
120120
S extends RedisScripts = {},
121-
RESP extends RespVersions = 2,
121+
RESP extends RespVersions = 3,
122122
TYPE_MAPPING extends TypeMapping = {},
123123
// POLICIES extends CommandPolicies = {}
124124
> = (
@@ -222,7 +222,7 @@ export default class RedisCluster<
222222
M extends RedisModules = {},
223223
F extends RedisFunctions = {},
224224
S extends RedisScripts = {},
225-
RESP extends RespVersions = 2,
225+
RESP extends RespVersions = 3,
226226
TYPE_MAPPING extends TypeMapping = {},
227227
// POLICIES extends CommandPolicies = {}
228228
>(config?: ClusterCommander<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>) {
@@ -253,7 +253,7 @@ export default class RedisCluster<
253253
M extends RedisModules = {},
254254
F extends RedisFunctions = {},
255255
S extends RedisScripts = {},
256-
RESP extends RespVersions = 2,
256+
RESP extends RespVersions = 3,
257257
TYPE_MAPPING extends TypeMapping = {},
258258
// POLICIES extends CommandPolicies = {}
259259
>(options?: RedisClusterOptions<M, F, S, RESP, TYPE_MAPPING/*, POLICIES*/>) {

packages/client/lib/cluster/multi-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export default class RedisClusterMultiCommand<REPLIES = []> {
179179
M extends RedisModules = Record<string, never>,
180180
F extends RedisFunctions = Record<string, never>,
181181
S extends RedisScripts = Record<string, never>,
182-
RESP extends RespVersions = 2
182+
RESP extends RespVersions = 3
183183
>(config?: CommanderConfig<M, F, S, RESP>) {
184184
return attachConfig({
185185
BaseClass: RedisClusterMultiCommand,

0 commit comments

Comments
 (0)