Skip to content

Commit

Permalink
Node: replace decoder by DecoderOption and route by `RouteOptio…
Browse files Browse the repository at this point in the history
…n` in API (#2234)


Signed-off-by: Prateek Kumar <prateek.kumar@improving.com>
Signed-off-by: prateek-kumar-improving <prateek.kumar@improving.com>
  • Loading branch information
prateek-kumar-improving authored Sep 7, 2024
1 parent c356b6c commit 9d35b30
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 428 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Changes
* Node: Added binary variant to HSCAN command ([#2240](https://github.com/valkey-io/valkey-glide/pull/2240))
* Node: replace decoder by DecoderOption and route by RouteOption in API([#2234](https://github.com/valkey-io/valkey-glide/pull/2234/))
* Node: Added binary variant to sorted set commands ([#2190](https://github.com/valkey-io/valkey-glide/pull/2190), [#2210](https://github.com/valkey-io/valkey-glide/pull/2210))
* Node: Added binary variant for MSET, MSETNX commands ([#2229](https://github.com/valkey-io/valkey-glide/pull/2229))
* Node: Added binary variant to HASH commands ([#2194](https://github.com/valkey-io/valkey-glide/pull/2194))
Expand Down
275 changes: 162 additions & 113 deletions node/src/BaseClient.ts

Large diffs are not rendered by default.

86 changes: 36 additions & 50 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,19 @@ export class GlideClient extends BaseClient {
* @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
*
* @param transaction - A {@link Transaction} object containing a list of commands to be executed.
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns A list of results corresponding to the execution of each command in the transaction.
* If a command returns a value, it will be included in the list. If a command doesn't return a value,
* the list entry will be `null`.
* If the transaction failed due to a `WATCH` command, `exec` will return `null`.
*/
public async exec(
transaction: Transaction,
decoder?: Decoder,
options?: DecoderOption,
): Promise<ReturnType[] | null> {
return this.createWritePromise<ReturnType[] | null>(
transaction.commands,
{ decoder: decoder },
options,
).then((result) =>
this.processResultWithSetCommands(
result,
Expand All @@ -208,6 +207,10 @@ export class GlideClient extends BaseClient {
*
* @see {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command|Valkey Glide Wiki} for details on the restrictions and limitations of the custom command API.
*
* @param args - A list including the command name and arguments for the custom command.
* @param options - (Optional) See {@link DecoderOption}.
* @returns The executed custom command return value.
*
* @example
* ```typescript
* // Example usage of customCommand method to retrieve pub/sub clients
Expand All @@ -217,11 +220,9 @@ export class GlideClient extends BaseClient {
*/
public async customCommand(
args: GlideString[],
decoder?: Decoder,
options?: DecoderOption,
): Promise<ReturnType> {
return this.createWritePromise(createCustomCommand(args), {
decoder: decoder,
});
return this.createWritePromise(createCustomCommand(args), options);
}

/**
Expand Down Expand Up @@ -255,9 +256,7 @@ export class GlideClient extends BaseClient {
message?: GlideString;
} & DecoderOption,
): Promise<GlideString> {
return this.createWritePromise(createPing(options?.message), {
decoder: options?.decoder,
});
return this.createWritePromise(createPing(options?.message), options);
}

/**
Expand Down Expand Up @@ -301,8 +300,7 @@ export class GlideClient extends BaseClient {
*
* @see {@link https://valkey.io/commands/client-getname/|valkey.io} for more details.
*
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns The name of the client connection as a string if a name is set, or `null` if no name is assigned.
*
* @example
Expand All @@ -312,10 +310,10 @@ export class GlideClient extends BaseClient {
* console.log(result); // Output: 'Client Name'
* ```
*/
public async clientGetName(decoder?: Decoder): Promise<GlideString | null> {
return this.createWritePromise(createClientGetName(), {
decoder: decoder,
});
public async clientGetName(
options?: DecoderOption,
): Promise<GlideString | null> {
return this.createWritePromise(createClientGetName(), options);
}

/**
Expand Down Expand Up @@ -381,8 +379,7 @@ export class GlideClient extends BaseClient {
* @see {@link https://valkey.io/commands/config-get/|valkey.io} for details.
*
* @param parameters - A list of configuration parameter names to retrieve values for.
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
*
* @returns A map of values corresponding to the configuration parameters.
*
Expand All @@ -395,11 +392,9 @@ export class GlideClient extends BaseClient {
*/
public async configGet(
parameters: string[],
decoder?: Decoder,
options?: DecoderOption,
): Promise<Record<string, GlideString>> {
return this.createWritePromise(createConfigGet(parameters), {
decoder: decoder,
});
return this.createWritePromise(createConfigGet(parameters), options);
}

/**
Expand Down Expand Up @@ -430,8 +425,7 @@ export class GlideClient extends BaseClient {
* @see {@link https://valkey.io/commands/echo|valkey.io} for more details.
*
* @param message - The message to be echoed back.
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns The provided `message`.
*
* @example
Expand All @@ -443,11 +437,9 @@ export class GlideClient extends BaseClient {
*/
public async echo(
message: GlideString,
decoder?: Decoder,
options?: DecoderOption,
): Promise<GlideString> {
return this.createWritePromise(createEcho(message), {
decoder,
});
return this.createWritePromise(createEcho(message), options);
}

/**
Expand Down Expand Up @@ -598,7 +590,7 @@ export class GlideClient extends BaseClient {
): Promise<GlideString> {
return this.createWritePromise(
createFunctionLoad(libraryCode, options?.replace),
{ decoder: options?.decoder },
options,
);
}

Expand Down Expand Up @@ -654,9 +646,7 @@ export class GlideClient extends BaseClient {
public async functionList(
options?: FunctionListOptions & DecoderOption,
): Promise<FunctionListResponse> {
return this.createWritePromise(createFunctionList(options), {
decoder: options?.decoder,
});
return this.createWritePromise(createFunctionList(options), options);
}

/**
Expand All @@ -669,8 +659,7 @@ export class GlideClient extends BaseClient {
* @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details.
* @remarks Since Valkey version 7.0.0.
*
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns A Record where the key is the node address and the value is a Record with two keys:
* - `"running_script"`: Information about the running script, or `null` if no script is running.
* - `"engines"`: Information about available engines and their stats.
Expand Down Expand Up @@ -706,11 +695,9 @@ export class GlideClient extends BaseClient {
* ```
*/
public async functionStats(
decoder?: Decoder,
options?: DecoderOption,
): Promise<FunctionStatsFullResponse> {
return this.createWritePromise(createFunctionStats(), {
decoder,
});
return this.createWritePromise(createFunctionStats(), options);
}

/**
Expand Down Expand Up @@ -886,9 +873,7 @@ export class GlideClient extends BaseClient {
key: GlideString,
options?: SortOptions & DecoderOption,
): Promise<(GlideString | null)[]> {
return this.createWritePromise(createSort(key, options), {
decoder: options?.decoder,
});
return this.createWritePromise(createSort(key, options), options);
}

/**
Expand Down Expand Up @@ -919,9 +904,10 @@ export class GlideClient extends BaseClient {
key: GlideString,
options?: SortOptions & DecoderOption,
): Promise<(GlideString | null)[]> {
return this.createWritePromise(createSortReadOnly(key, options), {
decoder: options?.decoder,
});
return this.createWritePromise(
createSortReadOnly(key, options),
options,
);
}

/**
Expand Down Expand Up @@ -981,9 +967,7 @@ export class GlideClient extends BaseClient {
* Returns a random existing key name from the currently selected database.
*
* @see {@link https://valkey.io/commands/randomkey/|valkey.io} for more details.
*
* @param decoder - (Optional) {@link Decoder} type which defines how to handle the response.
* If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used.
* @param options - (Optional) See {@link DecoderOption}.
* @returns A random existing key name from the currently selected database.
*
* @example
Expand All @@ -992,8 +976,10 @@ export class GlideClient extends BaseClient {
* console.log(result); // Output: "key12" - "key12" is a random existing key name from the currently selected database.
* ```
*/
public async randomKey(decoder?: Decoder): Promise<GlideString | null> {
return this.createWritePromise(createRandomKey(), { decoder: decoder });
public async randomKey(
options?: DecoderOption,
): Promise<GlideString | null> {
return this.createWritePromise(createRandomKey(), options);
}

/**
Expand Down
Loading

0 comments on commit 9d35b30

Please sign in to comment.