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))
* Java: Fix docs for stream commands ([#2086](https://github.com/valkey-io/valkey-glide/pull/2086))
* Node: Added binary variant to bitmap commands ([#2178](https://github.com/valkey-io/valkey-glide/pull/2178))
* Node: Added binary variant to generic commands ([#2158](https://github.com/valkey-io/valkey-glide/pull/2158))
Expand Down
8 changes: 5 additions & 3 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6320,7 +6320,7 @@ export class BaseClient {
* @remarks When in cluster mode, the command may route to multiple nodes when `keys` map to different hash slots.
*
* @param keys - The keys to watch.
* @returns A simple "OK" response.
* @returns A simple `"OK"` response.
*
* @example
* ```typescript
Expand All @@ -6339,8 +6339,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
82 changes: 57 additions & 25 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"`.
* + 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`.
*
* @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,
});
}

/** Returns the server time
Expand Down Expand Up @@ -923,7 +953,7 @@ export class GlideClient extends BaseClient {
*
* @see {@link https://valkey.io/commands/unwatch/|valkey.io} and {@link https://valkey.io/topics/transactions/#cas|Valkey Glide Wiki} for more details.
*
* @returns A simple "OK" response.
* @returns A simple `"OK"` response.
*
* @example
* ```typescript
Expand All @@ -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,
});
}
}
Loading
Loading