Skip to content
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

Node: Add binary variant to connection management commands. #2160

Merged
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Added/updated binary variant to connection management commands and WATCH/UNWATCH ([#2160](https://github.com/valkey-io/valkey-glide/pull/2160))
* Node: Added binary variant to generic commands ([#2158](https://github.com/valkey-io/valkey-glide/pull/2158))
* Node: Added binary variant to geo commands ([#2149](https://github.com/valkey-io/valkey-glide/pull/2149))
* Node: Added binary variant to HYPERLOGLOG commands ([#2176](https://github.com/valkey-io/valkey-glide/pull/2176))
Expand Down
6 changes: 4 additions & 2 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6336,8 +6336,10 @@ export class BaseClient {
* console.log(result); // Output: null - null is returned when the watched key is modified before transaction execution.
* ```
*/
public async watch(keys: string[]): Promise<"OK"> {
return this.createWritePromise(createWatch(keys));
public async watch(keys: GlideString[]): Promise<"OK"> {
return this.createWritePromise(createWatch(keys), {
decoder: Decoder.String,
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ export function createZPopMax(
/**
* @internal
*/
export function createEcho(message: string): command_request.Command {
export function createEcho(message: GlideString): command_request.Command {
return createCommand(RequestType.Echo, [message]);
}

Expand Down Expand Up @@ -3729,7 +3729,7 @@ export function createRandomKey(): command_request.Command {
}

/** @internal */
export function createWatch(keys: string[]): command_request.Command {
export function createWatch(keys: GlideString[]): command_request.Command {
return createCommand(RequestType.Watch, keys);
}

Expand Down
80 changes: 56 additions & 24 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,17 @@ export class GlideClient extends BaseClient {
});
}

/** Ping the Redis server.
/**
* Pings the server.
*
* @see {@link https://valkey.io/commands/ping/|valkey.io} for details.
*
* @param message - An optional message to include in the PING command.
* If not provided, the server will respond with "PONG".
* If provided, the server will respond with a copy of the message.
* @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.
* @returns - "PONG" if `message` is not provided, otherwise return a copy of `message`.
* @param options - (Optional) Additional parameters:
* - (Optional) `message` : a message to include in the `PING` command.
* + If not provided, the server will respond with "PONG".
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
* + If provided, the server will respond with a copy of the message.
* - (Optional) `decoder`: see {@link DecoderOption}.
* @returns "PONG" if `message` is not provided, otherwise return a copy of `message`.
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* ```typescript
Expand All @@ -248,10 +250,11 @@ export class GlideClient extends BaseClient {
* console.log(result); // Output: 'Hello'
* ```
*/
public async ping(options?: {
message?: GlideString;
decoder?: Decoder;
}): Promise<GlideString> {
public async ping(
options?: {
message?: GlideString;
} & DecoderOption,
): Promise<GlideString> {
return this.createWritePromise(createPing(options?.message), {
decoder: options?.decoder,
});
Expand All @@ -268,11 +271,13 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createInfo(options));
}

/** Change the currently selected Redis database.
/**
* Changes the currently selected database.
*
* @see {@link https://valkey.io/commands/select/|valkey.io} for details.
*
* @param index - The index of the database to select.
* @returns A simple OK response.
* @returns A simple "OK" response.
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* ```typescript
Expand All @@ -282,13 +287,19 @@ export class GlideClient extends BaseClient {
* ```
*/
public async select(index: number): Promise<"OK"> {
return this.createWritePromise(createSelect(index));
return this.createWritePromise(createSelect(index), {
decoder: Decoder.String,
});
}

/** Get the name of the primary's connection.
/**
* Gets the name of the primary's connection.
*
* @see {@link https://valkey.io/commands/client-getname/|valkey.io} for more details.
*
* @returns the name of the client connection as a string if a name is set, or null if no name is assigned.
* @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.
* @returns The name of the client connection as a string if a name is set, or `null` if no name is assigned.
*
* @example
* ```typescript
Expand All @@ -297,8 +308,10 @@ export class GlideClient extends BaseClient {
* console.log(result); // Output: 'Client Name'
* ```
*/
public async clientGetName(): Promise<string | null> {
return this.createWritePromise(createClientGetName());
public async clientGetName(decoder?: Decoder): Promise<GlideString | null> {
return this.createWritePromise(createClientGetName(), {
decoder: decoder,
});
}

/** Rewrite the configuration file with the current configuration.
Expand Down Expand Up @@ -334,10 +347,18 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createConfigResetStat());
}

/** Returns the current connection id.
/**
* Returns the current connection ID.
*
* @see {@link https://valkey.io/commands/client-id/|valkey.io} for details.
*
* @returns the id of the client.
* @returns The ID of the connection.
*
* @example
* ```typescript
* const result = await client.clientId();
* console.log("Connection id: " + result);
* ```
*/
public async clientId(): Promise<number> {
return this.createWritePromise(createClientId());
Expand Down Expand Up @@ -382,10 +403,14 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createConfigSet(parameters));
}

/** Echoes the provided `message` back.
/**
* Echoes the provided `message` back.
*
* @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.
* @returns The provided `message`.
*
* @example
Expand All @@ -395,8 +420,13 @@ export class GlideClient extends BaseClient {
* console.log(echoedMessage); // Output: 'valkey-glide'
* ```
*/
public async echo(message: string): Promise<string> {
return this.createWritePromise(createEcho(message));
public async echo(
message: GlideString,
decoder?: Decoder,
): Promise<GlideString> {
return this.createWritePromise(createEcho(message), {
decoder: decoder,
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
});
}

/** Returns the server time
Expand Down Expand Up @@ -934,6 +964,8 @@ export class GlideClient extends BaseClient {
* ```
*/
public async unwatch(): Promise<"OK"> {
return this.createWritePromise(createUnWatch());
return this.createWritePromise(createUnWatch(), {
decoder: Decoder.String,
});
}
}
112 changes: 69 additions & 43 deletions node/src/GlideClusterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,20 @@ export class GlideClusterClient extends BaseClient {
);
}

/** Ping the Redis server.
/**
* Pings the server.
*
* The command will be routed to all primary nodes, unless `route` is provided.
*
* @see {@link https://valkey.io/commands/ping/|valkey.io} for details.
*
* @param message - An optional message to include in the PING command.
* If not provided, the server will respond with "PONG".
* If provided, the server will respond with a copy of the message.
* @param route - The command will be routed to all primaries, unless `route` is provided, in which
* case the client will route the command to the nodes defined by `route`.
* @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.
* @returns - "PONG" if `message` is not provided, otherwise return a copy of `message`.
* @param options - (Optional) Additional parameters:
* - (Optional) `message` : a message to include in the `PING` command.
* + If not provided, the server will respond with "PONG".
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
* + If provided, the server will respond with a copy of the message.
* - (Optional) `route`: see {@link RouteOption}.
* - (Optional) `decoder`: see {@link DecoderOption}.
* @returns "PONG" if `message` is not provided, otherwise return a copy of `message`.
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* ```typescript
Expand All @@ -435,11 +437,12 @@ export class GlideClusterClient extends BaseClient {
* console.log(result); // Output: 'Hello'
* ```
*/
public async ping(options?: {
message?: GlideString;
route?: Routes;
decoder?: Decoder;
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
}): Promise<GlideString> {
public async ping(
options?: {
message?: GlideString;
} & RouteOption &
DecoderOption,
): Promise<GlideString> {
return this.createWritePromise(createPing(options?.message), {
route: toProtobufRoute(options?.route),
decoder: options?.decoder,
Expand All @@ -466,15 +469,18 @@ export class GlideClusterClient extends BaseClient {
);
}

/** Get the name of the connection to which the request is routed.
/**
* Gets the name of the connection to which the request is routed.
*
* The command will be routed to a random node, unless `route` is provided.
*
* @see {@link https://valkey.io/commands/client-getname/|valkey.io} for details.
*
* @param route - The command will be routed a random node, unless `route` is provided, in which
* case the client will route the command to the nodes defined by `route`.
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
*
* @returns - the name of the client connection as a string if a name is set, or null if no name is assigned.
* When specifying a route other than a single node, it returns a dictionary where each address is the key and
* its corresponding node response is the value.
* @returns - The name of the client connection as a string if a name is set, or `null` if no name is assigned.
* When specifying a route other than a single node, it returns a dictionary where each address is the key and
* its corresponding node response is the value.
*
* @example
* ```typescript
Expand All @@ -491,11 +497,14 @@ export class GlideClusterClient extends BaseClient {
* ```
*/
public async clientGetName(
route?: Routes,
): Promise<ClusterResponse<string | null>> {
return this.createWritePromise<ClusterResponse<string | null>>(
options?: RouteOption & DecoderOption,
): Promise<ClusterResponse<GlideString | null>> {
return this.createWritePromise<ClusterResponse<GlideString | null>>(
createClientGetName(),
{ route: toProtobufRoute(route) },
{
route: toProtobufRoute(options?.route),
decoder: options?.decoder,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

...options

should accomplish the same thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, not, because both have route but in different type

},
);
}

Expand Down Expand Up @@ -539,18 +548,29 @@ export class GlideClusterClient extends BaseClient {
});
}

/** Returns the current connection id.
/**
* Returns the current connection ID.
*
* The command will be routed to a random node, unless `route` is provided.
*
* @see {@link https://valkey.io/commands/client-id/|valkey.io} for details.
*
* @param route - The command will be routed to a random node, unless `route` is provided, in which
* case the client will route the command to the nodes defined by `route`.
* @returns the id of the client. When specifying a route other than a single node,
* it returns a dictionary where each address is the key and its corresponding node response is the value.
* @param options - (Optional) See {@link RouteOption}.
* @returns The ID of the connection. When specifying a route other than a single node,
* it returns a dictionary where each address is the key and its corresponding node response is the value.
*
* @example
* ```typescript
* const result = await client.clientId();
* console.log("Connection id: " + result);
* ```
*/
public async clientId(route?: Routes): Promise<ClusterResponse<number>> {
public async clientId(
options?: RouteOption,
): Promise<ClusterResponse<number>> {
return this.createWritePromise<ClusterResponse<number>>(
createClientId(),
{ route: toProtobufRoute(route) },
{ route: toProtobufRoute(options?.route) },
);
}

Expand Down Expand Up @@ -614,14 +634,17 @@ export class GlideClusterClient extends BaseClient {
});
}

/** Echoes the provided `message` back.
/**
* Echoes the provided `message` back.
*
* The command will be routed to a random node, unless `route` is provided.
*
* @see {@link https://valkey.io/commands/echo/|valkey.io} for details.
*
* @param message - The message to be echoed back.
* @param route - The command will be routed to a random node, unless `route` is provided, in which
* case the client will route the command to the nodes defined by `route`.
* @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
* @returns The provided `message`. When specifying a route other than a single node,
* it returns a dictionary where each address is the key and its corresponding node response is the value.
* it returns a dictionary where each address is the key and its corresponding node response is the value.
*
* @example
* ```typescript
Expand All @@ -637,11 +660,12 @@ export class GlideClusterClient extends BaseClient {
* ```
*/
public async echo(
message: string,
route?: Routes,
): Promise<ClusterResponse<string>> {
message: GlideString,
options?: RouteOption & DecoderOption,
): Promise<ClusterResponse<GlideString>> {
return this.createWritePromise(createEcho(message), {
route: toProtobufRoute(route),
route: toProtobufRoute(options?.route),
decoder: options?.decoder,
});
}

Expand Down Expand Up @@ -1344,10 +1368,11 @@ export class GlideClusterClient extends BaseClient {
* Flushes all the previously watched keys for a transaction. Executing a transaction will
* automatically flush all previously watched keys.
*
* The command will be routed to all primary nodes, unless `route` is provided
*
* @see {@link https://valkey.io/commands/unwatch/|valkey.io} and {@link https://valkey.io/topics/transactions/#cas|Valkey Glide Wiki} for more details.
*
* @param route - (Optional) The command will be routed to all primary nodes, unless `route` is provided,
* in which case the client will route the command to the nodes defined by `route`.
* @param options - (Optional) See {@link RouteOption}.
* @returns A simple "OK" response.
*
* @example
Expand All @@ -1358,9 +1383,10 @@ export class GlideClusterClient extends BaseClient {
* console.log(response); // Output: "OK"
* ```
*/
public async unwatch(route?: Routes): Promise<"OK"> {
public async unwatch(options?: RouteOption): Promise<"OK"> {
return this.createWritePromise(createUnWatch(), {
route: toProtobufRoute(route),
route: toProtobufRoute(options?.route),
decoder: Decoder.String,
});
}
}
Loading
Loading