Skip to content
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 binary variant to server management commands ([#2179](https://github.com/valkey-io/valkey-glide/pull/2179))
* 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))
* Node: Added FUNCTION DUMP and FUNCTION RESTORE commands ([#2129](https://github.com/valkey-io/valkey-glide/pull/2129), [#2173](https://github.com/valkey-io/valkey-glide/pull/2173))
Expand Down
26 changes: 15 additions & 11 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BaseClient, Decoder } from "src/BaseClient";
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
import { GlideClient } from "src/GlideClient";
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
import { GlideClusterClient } from "src/GlideClusterClient";
import { GlideClusterClient, Routes } from "src/GlideClusterClient";
import { GlideString } from "./BaseClient";
import { command_request } from "./ProtobufMessage";

Expand Down Expand Up @@ -89,7 +89,7 @@ function createCommand(
return singleCommand;
}

/** An extension to command option types. */
/** An extension to command option types with {@link Decoder}. */
export type DecoderOption = {
/**
* {@link Decoder} type which defines how to handle the response.
Expand All @@ -98,6 +98,15 @@ export type DecoderOption = {
decoder?: Decoder;
};

/** An extension to command option types with {@link Routes}. */
export type RouteOption = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this used in this file?
Maybe RouteOption should be defined in GlideClusterClient because it's not ever used here.

Thoughts?

/**
* Specifies the routing configuration for the command.
* The client will route the command to the nodes defined by `route`.
*/
route?: Routes;
};

/**
* @internal
*/
Expand Down Expand Up @@ -399,7 +408,7 @@ export function createConfigGet(parameters: string[]): command_request.Command {
* @internal
*/
export function createConfigSet(
parameters: Record<string, string>,
parameters: Record<string, GlideString>,
): command_request.Command {
return createCommand(
RequestType.ConfigSet,
Expand Down Expand Up @@ -2887,23 +2896,18 @@ export function createObjectRefcount(key: string): command_request.Command {
return createCommand(RequestType.ObjectRefCount, [key]);
}

/** Additional parameters for `LOLWUT` command. */
export type LolwutOptions = {
/**
* An optional argument that can be used to specify the version of computer art to generate.
*/
version?: number;
/**
* An optional argument that can be used to specify the output:
* For version `5`, those are length of the line, number of squares per row, and number of squares per column.
* For version `6`, those are number of columns and number of lines.
* - For version `5`, those are length of the line, number of squares per row, and number of squares per column.
* - For version `6`, those are number of columns and number of lines.
*/
parameters?: number[];
/**
* An optional argument specifies the type of decoding.
* Use Decoder.String to get the response as a String.
* Use Decoder.Bytes to get the response in a buffer.
*/
decoder?: Decoder;
};

/**
Expand Down
102 changes: 66 additions & 36 deletions node/src/GlideClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,19 @@ export class GlideClient extends BaseClient {
});
}

/** Get information and statistics about the Redis server.
/**
* Gets information and statistics about the server.
*
* @see {@link https://valkey.io/commands/info/|valkey.io} for details.
*
* @param options - A list of InfoSection values specifying which sections of information to retrieve.
* When no parameter is provided, the default option is assumed.
* @returns a string containing the information for the sections requested.
* @param sections - (Optional) A list of {@link InfoOptions} values specifying which sections of information to retrieve.
* When no parameter is provided, the {@link InfoOptions.Default|default option} is assumed.
* @returns A string containing the information for the sections requested.
*/
public async info(options?: InfoOptions[]): Promise<string> {
return this.createWritePromise(createInfo(options));
public async info(sections?: InfoOptions[]): Promise<string> {
return this.createWritePromise(createInfo(sections), {
decoder: Decoder.String,
});
}

/** Change the currently selected Redis database.
Expand Down Expand Up @@ -300,7 +304,9 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createClientGetName());
}

/** Rewrite the configuration file with the current configuration.
/**
* Rewrites the configuration file with the current configuration.
*
* @see {@link https://valkey.io/commands/config-rewrite/|valkey.io} for details.
*
* @returns "OK" when the configuration was rewritten properly. Otherwise, an error is thrown.
Expand All @@ -313,10 +319,13 @@ export class GlideClient extends BaseClient {
* ```
*/
public async configRewrite(): Promise<"OK"> {
return this.createWritePromise(createConfigRewrite());
return this.createWritePromise(createConfigRewrite(), {
decoder: Decoder.String,
});
}

/** Resets the statistics reported by Redis using the INFO and LATENCY HISTOGRAM commands.
/**
* Resets the statistics reported by the server using the `INFO` and `LATENCY HISTOGRAM` commands.
*
* @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details.
*
Expand All @@ -330,7 +339,9 @@ export class GlideClient extends BaseClient {
* ```
*/
public async configResetStat(): Promise<"OK"> {
return this.createWritePromise(createConfigResetStat());
return this.createWritePromise(createConfigResetStat(), {
decoder: Decoder.String,
});
}

/** Returns the current connection id.
Expand All @@ -342,11 +353,14 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createClientId());
}

/** Reads the configuration parameters of a running Redis server.
/**
* Reads the configuration parameters of the running server.
*
* @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.
*
* @returns A map of values corresponding to the configuration parameters.
*
Expand All @@ -359,16 +373,19 @@ export class GlideClient extends BaseClient {
*/
public async configGet(
parameters: string[],
): Promise<Record<string, string>> {
return this.createWritePromise(createConfigGet(parameters));
decoder?: Decoder,
): Promise<Record<string, GlideString>> {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I assume that config parameter names are defined by the server, so all of them are simple strings.
Can I assume that parameter values are simple strings as well?

return this.createWritePromise(createConfigGet(parameters), {
decoder: decoder,
});
}

/**
* Set configuration parameters to the specified values.
* Sets configuration parameters to the specified values.
*
* @see {@link https://valkey.io/commands/config-set/|valkey.io} for details.
* @param parameters - A List of keyValuePairs consisting of configuration parameters and their respective values to set.
* @returns "OK" when the configuration was set properly. Otherwise an error is thrown.
* @param parameters - A map consisting of configuration parameters and their respective values to set.
Comment thread
Yury-Fridlyand marked this conversation as resolved.
* @returns `"OK"` when the configuration was set properly. Otherwise an error is thrown.
*
* @example
* ```typescript
Expand All @@ -377,8 +394,12 @@ export class GlideClient extends BaseClient {
* console.log(result); // Output: 'OK'
* ```
*/
public async configSet(parameters: Record<string, string>): Promise<"OK"> {
return this.createWritePromise(createConfigSet(parameters));
public async configSet(
parameters: Record<string, GlideString>,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

same here

): Promise<"OK"> {
return this.createWritePromise(createConfigSet(parameters), {
decoder: Decoder.String,
});
}

/** Echoes the provided `message` back.
Expand All @@ -398,22 +419,24 @@ export class GlideClient extends BaseClient {
return this.createWritePromise(createEcho(message));
}

/** Returns the server time
/**
* Returns the server time.
*
* @see {@link https://valkey.io/commands/time/|valkey.io} for details.
*
* @returns - The current server time as a two items `array`:
* A Unix timestamp and the amount of microseconds already elapsed in the current second.
* The returned `array` is in a [Unix timestamp, Microseconds already elapsed] format.
* @returns The current server time as an `array` with two items:
* - A Unix timestamp,
* - The amount of microseconds already elapsed in the current second.
*
* @example
* ```typescript
* // Example usage of time command
* const result = await client.time();
* console.log(result); // Output: ['1710925775', '913580']
* console.log(await client.time()); // Output: ['1710925775', '913580']
* ```
*/
public async time(): Promise<[string, string]> {
return this.createWritePromise(createTime());
return this.createWritePromise(createTime(), {
decoder: Decoder.String,
});
}

/**
Expand Down Expand Up @@ -482,7 +505,7 @@ export class GlideClient extends BaseClient {
*
* @see {@link https://valkey.io/commands/lolwut/|valkey.io} for more details.
*
* @param options - The LOLWUT options
* @param options - (Optional) The LOLWUT options - see {@link LolwutOptions}.
* @returns A piece of generative computer art along with the current server version.
*
* @example
Expand All @@ -492,7 +515,9 @@ export class GlideClient extends BaseClient {
* ```
*/
public async lolwut(options?: LolwutOptions): Promise<string> {
return this.createWritePromise(createLolwut(options));
return this.createWritePromise(createLolwut(options), {
decoder: Decoder.String,
});
}

/**
Expand Down Expand Up @@ -710,35 +735,39 @@ export class GlideClient extends BaseClient {
*
* @see {@link https://valkey.io/commands/flushall/|valkey.io} for more details.
*
* @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
* @returns `OK`.
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
* @returns `"OK"`.
*
* @example
* ```typescript
* const result = await client.flushall(FlushMode.SYNC);
* console.log(result); // Output: 'OK'
* ```
*/
public async flushall(mode?: FlushMode): Promise<string> {
return this.createWritePromise(createFlushAll(mode));
public async flushall(mode?: FlushMode): Promise<"OK"> {
return this.createWritePromise(createFlushAll(mode), {
decoder: Decoder.String,
});
}

/**
* Deletes all the keys of the currently selected database. This command never fails.
*
* @see {@link https://valkey.io/commands/flushdb/|valkey.io} for more details.
*
* @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
* @returns `OK`.
* @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}.
* @returns `"OK"`.
*
* @example
* ```typescript
* const result = await client.flushdb(FlushMode.SYNC);
* console.log(result); // Output: 'OK'
* ```
*/
public async flushdb(mode?: FlushMode): Promise<string> {
return this.createWritePromise(createFlushDB(mode));
public async flushdb(mode?: FlushMode): Promise<"OK"> {
return this.createWritePromise(createFlushDB(mode), {
decoder: Decoder.String,
});
}

/**
Expand Down Expand Up @@ -881,6 +910,7 @@ export class GlideClient extends BaseClient {
* @see {@link https://valkey.io/commands/lastsave/|valkey.io} for more details.
*
* @returns `UNIX TIME` of the last DB save executed with success.
*
* @example
* ```typescript
* const timestamp = await client.lastsave();
Expand Down
Loading