diff --git a/CHANGELOG.md b/CHANGELOG.md index a7296b9e38..b961a6c0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/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)) diff --git a/node/npm/glide/index.ts b/node/npm/glide/index.ts index 68efeadfda..65840cf7a8 100644 --- a/node/npm/glide/index.ts +++ b/node/npm/glide/index.ts @@ -118,6 +118,7 @@ function initialize() { SlotKeyTypes, TimeUnit, RouteByAddress, + RouteOption, Routes, RestoreOptions, SingleNodeRoute, @@ -227,6 +228,7 @@ function initialize() { TimeUnit, ReturnTypeXinfoStream, RouteByAddress, + RouteOption, Routes, RestoreOptions, SingleNodeRoute, diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 16d23e62e9..123221718c 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -24,7 +24,6 @@ import { BitwiseOperation, Boundary, CoordOrigin, // eslint-disable-line @typescript-eslint/no-unused-vars - DecoderOption, ExpireOptions, GeoAddOptions, GeoBoxShape, // eslint-disable-line @typescript-eslint/no-unused-vars @@ -289,6 +288,15 @@ export enum Decoder { String, } +/** An extension to command option types with {@link Decoder}. */ +export type DecoderOption = { + /** + * {@link Decoder} type which defines how to handle the response. + * If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used. + */ + decoder?: Decoder; +}; + /** * Our purpose in creating PointerResponse type is to mark when response is of number/long pointer response type. * Consequently, when the response is returned, we can check whether it is instanceof the PointerResponse type and pass it to the Rust core function with the proper parameters. diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 0b7aeb3c73..d70338a349 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -6,11 +6,11 @@ import { createLeakedStringVec, MAX_REQUEST_ARGS_LEN } from "glide-rs"; import Long from "long"; /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -import { BaseClient, Decoder } from "src/BaseClient"; +import { BaseClient } 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, Routes } from "src/GlideClusterClient"; +import { GlideClusterClient } from "src/GlideClusterClient"; import { GlideString } from "./BaseClient"; import { command_request } from "./ProtobufMessage"; @@ -89,24 +89,6 @@ function createCommand( return singleCommand; } -/** An extension to command option types with {@link Decoder}. */ -export type DecoderOption = { - /** - * {@link Decoder} type which defines how to handle the response. - * If not set, the {@link BaseClientConfiguration.defaultDecoder|default decoder} will be used. - */ - decoder?: Decoder; -}; - -/** An extension to command option types with {@link Routes}. */ -export type RouteOption = { - /** - * Specifies the routing configuration for the command. - * The client will route the command to the nodes defined by `route`. - */ - route?: Routes; -}; - /** * @internal */ @@ -408,7 +390,7 @@ export function createConfigGet(parameters: string[]): command_request.Command { * @internal */ export function createConfigSet( - parameters: Record, + parameters: Record, ): command_request.Command { return createCommand( RequestType.ConfigSet, @@ -2902,6 +2884,7 @@ export function createObjectRefcount( 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. @@ -2909,16 +2892,10 @@ export type LolwutOptions = { 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; }; /** diff --git a/node/src/GlideClient.ts b/node/src/GlideClient.ts index ac2ed3f1ec..ef64b570a1 100644 --- a/node/src/GlideClient.ts +++ b/node/src/GlideClient.ts @@ -7,13 +7,13 @@ import { BaseClient, BaseClientConfiguration, Decoder, + DecoderOption, GlideString, PubSubMsg, ReadFrom, // eslint-disable-line @typescript-eslint/no-unused-vars ReturnType, } from "./BaseClient"; import { - DecoderOption, FlushMode, FunctionListOptions, FunctionListResponse, @@ -260,15 +260,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, {@link InfoOptions.Default|Default} is assumed. + * @returns A string containing the information for the sections requested. */ - public async info(options?: InfoOptions[]): Promise { - return this.createWritePromise(createInfo(options)); + public async info(sections?: InfoOptions[]): Promise { + return this.createWritePromise(createInfo(sections), { + decoder: Decoder.String, + }); } /** @@ -314,7 +318,9 @@ export class GlideClient extends BaseClient { }); } - /** 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. @@ -327,10 +333,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. * @@ -344,7 +353,9 @@ export class GlideClient extends BaseClient { * ``` */ public async configResetStat(): Promise<"OK"> { - return this.createWritePromise(createConfigResetStat()); + return this.createWritePromise(createConfigResetStat(), { + decoder: Decoder.String, + }); } /** @@ -364,11 +375,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. * @@ -381,16 +395,19 @@ export class GlideClient extends BaseClient { */ public async configGet( parameters: string[], - ): Promise> { - return this.createWritePromise(createConfigGet(parameters)); + decoder?: Decoder, + ): Promise> { + 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. + * @returns `"OK"` when the configuration was set properly. Otherwise an error is thrown. * * @example * ```typescript @@ -399,8 +416,12 @@ export class GlideClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async configSet(parameters: Record): Promise<"OK"> { - return this.createWritePromise(createConfigSet(parameters)); + public async configSet( + parameters: Record, + ): Promise<"OK"> { + return this.createWritePromise(createConfigSet(parameters), { + decoder: Decoder.String, + }); } /** @@ -429,22 +450,24 @@ export class GlideClient extends BaseClient { }); } - /** 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, + }); } /** @@ -513,7 +536,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 @@ -523,7 +546,9 @@ export class GlideClient extends BaseClient { * ``` */ public async lolwut(options?: LolwutOptions): Promise { - return this.createWritePromise(createLolwut(options)); + return this.createWritePromise(createLolwut(options), { + decoder: Decoder.String, + }); } /** @@ -741,8 +766,8 @@ 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 @@ -750,8 +775,10 @@ export class GlideClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async flushall(mode?: FlushMode): Promise { - return this.createWritePromise(createFlushAll(mode)); + public async flushall(mode?: FlushMode): Promise<"OK"> { + return this.createWritePromise(createFlushAll(mode), { + decoder: Decoder.String, + }); } /** @@ -759,8 +786,8 @@ export class GlideClient extends BaseClient { * * @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 @@ -768,8 +795,10 @@ export class GlideClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async flushdb(mode?: FlushMode): Promise { - return this.createWritePromise(createFlushDB(mode)); + public async flushdb(mode?: FlushMode): Promise<"OK"> { + return this.createWritePromise(createFlushDB(mode), { + decoder: Decoder.String, + }); } /** diff --git a/node/src/GlideClusterClient.ts b/node/src/GlideClusterClient.ts index ed3492cd3d..193d49b7d5 100644 --- a/node/src/GlideClusterClient.ts +++ b/node/src/GlideClusterClient.ts @@ -7,13 +7,13 @@ import { BaseClient, BaseClientConfiguration, Decoder, + DecoderOption, GlideString, PubSubMsg, ReadFrom, // eslint-disable-line @typescript-eslint/no-unused-vars ReturnType, } from "./BaseClient"; import { - DecoderOption, FlushMode, FunctionListOptions, FunctionListResponse, @@ -21,7 +21,6 @@ import { FunctionStatsSingleResponse, InfoOptions, LolwutOptions, - RouteOption, SortClusterOptions, createClientGetName, createClientId, @@ -62,6 +61,15 @@ import { RequestError } from "./Errors"; import { command_request, connection_request } from "./ProtobufMessage"; import { ClusterTransaction } from "./Transaction"; +/** An extension to command option types with {@link Routes}. */ +export type RouteOption = { + /** + * Specifies the routing configuration for the command. + * The client will route the command to the nodes defined by `route`. + */ + route?: Routes; +}; + /** * Represents a manually configured interval for periodic checks. */ @@ -449,23 +457,27 @@ export class GlideClusterClient extends BaseClient { }); } - /** Get information and statistics about the Redis server. + /** + * Gets information and statistics about the server. + * + * The command will be routed to all primary nodes, unless `route` is provided. + * * @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. - * @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`. - * @returns a string containing the information for the sections requested. 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) Additional parameters: + * - (Optional) `sections`: a list of {@link InfoOptions} values specifying which sections of information to retrieve. + * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed. + * - (Optional) `route`: see {@link RouteOption}. + * @returns A string containing the information for the sections requested. + * 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. */ public async info( - options?: InfoOptions[], - route?: Routes, + options?: { sections?: InfoOptions[] } & RouteOption, ): Promise> { return this.createWritePromise>( - createInfo(options), - { route: toProtobufRoute(route) }, + createInfo(options?.sections), + { route: toProtobufRoute(options?.route), decoder: Decoder.String }, ); } @@ -508,12 +520,16 @@ export class GlideClusterClient extends BaseClient { ); } - /** Rewrite the configuration file with the current configuration. + /** + * Rewrites the configuration file with the current configuration. + * + * The command will be routed to a all nodes, unless `route` is provided. + * * @see {@link https://valkey.io/commands/config-rewrite/|valkey.io} for details. * - * @param route - The command will be routed to all nodes, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. - * @returns "OK" when the configuration was rewritten properly. Otherwise, an error is thrown. + * @param route - (Optional) Specifies the routing configuration for the command. + * The client will route the command to the nodes defined by `route`. + * @returns `"OK"` when the configuration was rewritten properly. Otherwise, an error is thrown. * * @example * ```typescript @@ -525,15 +541,20 @@ export class GlideClusterClient extends BaseClient { public async configRewrite(route?: Routes): Promise<"OK"> { return this.createWritePromise(createConfigRewrite(), { route: toProtobufRoute(route), + 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. + * + * The command will be routed to all nodes, unless `route` is provided. + * * @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details. * - * @param route - The command will be routed to all nodes, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. - * @returns always "OK". + * @param route - (Optional) Specifies the routing configuration for the command. + * The client will route the command to the nodes defined by `route`. + * @returns always `"OK"`. * * @example * ```typescript @@ -545,6 +566,7 @@ export class GlideClusterClient extends BaseClient { public async configResetStat(route?: Routes): Promise<"OK"> { return this.createWritePromise(createConfigResetStat(), { route: toProtobufRoute(route), + decoder: Decoder.String, }); } @@ -574,16 +596,18 @@ export class GlideClusterClient extends BaseClient { ); } - /** Reads the configuration parameters of a running Redis server. + /** + * Reads the configuration parameters of the running server. + * + * The command will be routed to a random node, unless `route` is provided. + * * @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 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`. - * If `route` is not provided, the command will be sent to a random node. + * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}. * * @returns A map of values corresponding to the configuration parameters. 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 @@ -601,21 +625,23 @@ export class GlideClusterClient extends BaseClient { */ public async configGet( parameters: string[], - route?: Routes, - ): Promise>> { - return this.createWritePromise>>( - createConfigGet(parameters), - { route: toProtobufRoute(route) }, - ); + options?: RouteOption & DecoderOption, + ): Promise>> { + return this.createWritePromise(createConfigGet(parameters), { + route: toProtobufRoute(options?.route), + decoder: options?.decoder, + }); } - /** Set configuration parameters to the specified values. + /** + * Sets configuration parameters to the specified values. + * + * The command will be routed to all nodes, unless `route` is provided. + * * @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. - * @param route - The command will be routed to all nodes, unless `route` is provided, in which - * case the client will route the command to the nodes defined by `route`. - * If `route` is not provided, the command will be sent to the all nodes. + * @param parameters - A map consisting of configuration parameters and their respective values to set. + * @param options - (Optional) See {@link RouteOption}. * @returns "OK" when the configuration was set properly. Otherwise an error is thrown. * * @example @@ -626,11 +652,12 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async configSet( - parameters: Record, - route?: Routes, + parameters: Record, + options?: RouteOption, ): Promise<"OK"> { return this.createWritePromise(createConfigSet(parameters), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } @@ -669,15 +696,19 @@ export class GlideClusterClient extends BaseClient { }); } - /** Returns the server time. + /** + * Returns the server time. + * + * The command will be routed to a random node, unless `route` is provided. + * * @see {@link https://valkey.io/commands/time/|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`. + * @param options - (Optional) See {@link RouteOption}. + * + * @returns The current server time as an `array` with two items: + * - A Unix timestamp, + * - The amount of microseconds already elapsed in the current second. * - * @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. * 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. * @@ -696,10 +727,11 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async time( - route?: Routes, + options?: RouteOption, ): Promise> { return this.createWritePromise(createTime(), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } @@ -736,11 +768,11 @@ export class GlideClusterClient extends BaseClient { /** * Displays a piece of generative computer art and the server version. * + * The command will be routed to a random node, unless `route` is provided. + * * @see {@link https://valkey.io/commands/lolwut/|valkey.io} for details. * - * @param options - The LOLWUT options. - * @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) The LOLWUT options - see {@link LolwutOptions} and {@link RouteOption}. * @returns A piece of generative computer art along with the current server version. * * @example @@ -750,12 +782,11 @@ export class GlideClusterClient extends BaseClient { * ``` */ public async lolwut( - options?: LolwutOptions, - route?: Routes, + options?: LolwutOptions & RouteOption, ): Promise> { return this.createWritePromise(createLolwut(options), { - decoder: options?.decoder, - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } @@ -1074,11 +1105,13 @@ export class GlideClusterClient extends BaseClient { /** * Deletes all the keys of all the existing databases. This command never fails. * + * The command will be routed to all primary nodes, unless `route` is provided. + * * @see {@link https://valkey.io/commands/flushall/|valkey.io} for details. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. - * @param route - 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) Additional parameters: + * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * - (Optional) `route`: see {@link RouteOption}. * @returns `OK`. * * @example @@ -1087,20 +1120,27 @@ export class GlideClusterClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async flushall(mode?: FlushMode, route?: Routes): Promise { - return this.createWritePromise(createFlushAll(mode), { - route: toProtobufRoute(route), + public async flushall( + options?: { + mode?: FlushMode; + } & RouteOption, + ): Promise<"OK"> { + return this.createWritePromise(createFlushAll(options?.mode), { + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } /** * Deletes all the keys of the currently selected database. This command never fails. * + * The command will be routed to all primary nodes, unless `route` is provided. + * * @see {@link https://valkey.io/commands/flushdb/|valkey.io} for details. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. - * @param route - 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) Additional parameters: + * - (Optional) `mode`: the flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * - (Optional) `route`: see {@link RouteOption}. * @returns `OK`. * * @example @@ -1109,19 +1149,25 @@ export class GlideClusterClient extends BaseClient { * console.log(result); // Output: 'OK' * ``` */ - public async flushdb(mode?: FlushMode, route?: Routes): Promise { - return this.createWritePromise(createFlushDB(mode), { - route: toProtobufRoute(route), + public async flushdb( + options?: { + mode?: FlushMode; + } & RouteOption, + ): Promise<"OK"> { + return this.createWritePromise(createFlushDB(options?.mode), { + route: toProtobufRoute(options?.route), + decoder: Decoder.String, }); } /** * Returns the number of keys in the database. * + * The command will be routed to all nodes, unless `route` is provided. + * * @see {@link https://valkey.io/commands/dbsize/|valkey.io} for details. - - * @param route - 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 The number of keys in the database. * In the case of routing the query to multiple nodes, returns the aggregated number of keys across the different nodes. * @@ -1131,9 +1177,11 @@ export class GlideClusterClient extends BaseClient { * console.log("Number of keys across all primary nodes: ", numKeys); * ``` */ - public async dbsize(route?: Routes): Promise> { + public async dbsize( + options?: RouteOption, + ): Promise> { return this.createWritePromise(createDBSize(), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), }); } @@ -1321,10 +1369,11 @@ export class GlideClusterClient extends BaseClient { * Returns `UNIX TIME` of the last DB save timestamp or startup timestamp if no save * was made since then. * + * The command will be routed to a random node, unless `route` is provided. + * * @see {@link https://valkey.io/commands/lastsave/|valkey.io} for details. * - * @param route - (Optional) 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}. * @returns `UNIX TIME` of the last DB save executed with success. * * @example @@ -1333,9 +1382,11 @@ export class GlideClusterClient extends BaseClient { * console.log("Last DB save was done at " + timestamp); * ``` */ - public async lastsave(route?: Routes): Promise> { + public async lastsave( + options?: RouteOption, + ): Promise> { return this.createWritePromise(createLastSave(), { - route: toProtobufRoute(route), + route: toProtobufRoute(options?.route), }); } diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index f4982236e1..0b9765b281 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -405,16 +405,18 @@ export class BaseTransaction> { return this.addAndReturn(createPing(message)); } - /** 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. + * @param sections - (Optional) A list of {@link InfoOptions} values specifying which sections of information to retrieve. + * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed. * - * Command Response - a string containing the information for the sections requested. + * Command Response - A string containing the information for the sections requested. */ - public info(options?: InfoOptions[]): T { - return this.addAndReturn(createInfo(options)); + public info(sections?: InfoOptions[]): T { + return this.addAndReturn(createInfo(sections)); } /** @@ -478,7 +480,9 @@ export class BaseTransaction> { return this.addAndReturn(createClientGetName()); } - /** Rewrite the configuration file with the current configuration. + /** + * Rewrites the configuration file with the current configuration. + * * @see {@link https://valkey.io/commands/select/|valkey.io} for details. * * Command Response - "OK" when the configuration was rewritten properly. Otherwise, the transaction fails with an error. @@ -487,7 +491,9 @@ export class BaseTransaction> { return this.addAndReturn(createConfigRewrite()); } - /** Resets the statistics reported by Redis using the INFO and LATENCY HISTOGRAM commands. + /** + * Resets the statistics reported by Redis using the `INFO` and `LATENCY HISTOGRAM` commands. + * * @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details. * * Command Response - always "OK". @@ -755,7 +761,9 @@ export class BaseTransaction> { return this.addAndReturn(createBitField(key, subcommands, true)); } - /** 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. @@ -767,14 +775,16 @@ export class BaseTransaction> { return this.addAndReturn(createConfigGet(parameters)); } - /** 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. + * @param parameters - A map consisting of configuration parameters and their respective values to set. * * Command Response - "OK" when the configuration was set properly. Otherwise, the transaction fails with an error. */ - public configSet(parameters: Record): T { + public configSet(parameters: Record): T { return this.addAndReturn(createConfigSet(parameters)); } @@ -2541,12 +2551,14 @@ export class BaseTransaction> { return this.addAndReturn(createXInfoGroups(key)); } - /** Returns the server time. + /** + * Returns the server time. + * * @see {@link https://valkey.io/commands/time/|valkey.io} for details. * - * Command Response - 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. + * Command Response - The current server time as an `array` with two items: + * - A Unix timestamp, + * - The amount of microseconds already elapsed in the current second. */ public time(): T { return this.addAndReturn(createTime()); @@ -3139,7 +3151,7 @@ export class BaseTransaction> { * * @see {@link https://valkey.io/commands/lolwut/|valkey.io} for details. * - * @param options - The LOLWUT options. + * @param options - (Optional) The LOLWUT options - see {@link LolwutOptions}. * * Command Response - A piece of generative computer art along with the current server version. */ @@ -3304,9 +3316,9 @@ export class BaseTransaction> { * * @see {@link https://valkey.io/commands/flushall/|valkey.io} for details. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. * - * Command Response - `OK`. + * Command Response - `"OK"`. */ public flushall(mode?: FlushMode): T { return this.addAndReturn(createFlushAll(mode)); @@ -3317,9 +3329,9 @@ export class BaseTransaction> { * * @see {@link https://valkey.io/commands/flushdb/|valkey.io} for details. * - * @param mode - The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. + * @param mode - (Optional) The flushing mode, could be either {@link FlushMode.SYNC} or {@link FlushMode.ASYNC}. * - * Command Response - `OK`. + * Command Response - `"OK"`. */ public flushdb(mode?: FlushMode): T { return this.addAndReturn(createFlushDB(mode)); diff --git a/node/tests/GlideClusterClient.test.ts b/node/tests/GlideClusterClient.test.ts index c1f7f4e389..4f7a6203bd 100644 --- a/node/tests/GlideClusterClient.test.ts +++ b/node/tests/GlideClusterClient.test.ts @@ -111,12 +111,12 @@ describe("GlideClusterClient", () => { getClientConfigurationOption(cluster.getAddresses(), protocol), ); const info_server = getFirstResult( - await client.info([InfoOptions.Server]), + await client.info({ sections: [InfoOptions.Server] }), ); expect(info_server).toEqual(expect.stringContaining("# Server")); const infoReplicationValues = Object.values( - await client.info([InfoOptions.Replication]), + await client.info({ sections: [InfoOptions.Replication] }), ); const replicationInfo = intoArray(infoReplicationValues); @@ -135,10 +135,10 @@ describe("GlideClusterClient", () => { client = await GlideClusterClient.createClient( getClientConfigurationOption(cluster.getAddresses(), protocol), ); - const result = await client.info( - [InfoOptions.Server], - "randomNode", - ); + const result = await client.info({ + sections: [InfoOptions.Server], + route: "randomNode", + }); expect(result).toEqual(expect.stringContaining("# Server")); expect(result).toEqual(expect.not.stringContaining("# Errorstats")); }, @@ -216,9 +216,11 @@ describe("GlideClusterClient", () => { getClientConfigurationOption(cluster.getAddresses(), protocol), ); await expect( - client.info(undefined, { - type: "routeByAddress", - host: "foo", + client.info({ + route: { + type: "routeByAddress", + host: "foo", + }, }), ).rejects.toThrowError(RequestError); }, @@ -571,29 +573,31 @@ describe("GlideClusterClient", () => { ); // test with multi-node route - const result1 = await client.lolwut({}, "allNodes"); + const result1 = await client.lolwut({ route: "allNodes" }); expect(intoString(result1)).toEqual( expect.stringContaining("Redis ver. "), ); - const result2 = await client.lolwut( - { version: 2, parameters: [10, 20] }, - "allNodes", - ); + const result2 = await client.lolwut({ + version: 2, + parameters: [10, 20], + route: "allNodes", + }); expect(intoString(result2)).toEqual( expect.stringContaining("Redis ver. "), ); // test with single-node route - const result3 = await client.lolwut({}, "randomNode"); + const result3 = await client.lolwut({ route: "randomNode" }); expect(intoString(result3)).toEqual( expect.stringContaining("Redis ver. "), ); - const result4 = await client.lolwut( - { version: 2, parameters: [10, 20] }, - "randomNode", - ); + const result4 = await client.lolwut({ + version: 2, + parameters: [10, 20], + route: "randomNode", + }); expect(intoString(result4)).toEqual( expect.stringContaining("Redis ver. "), ); @@ -698,12 +702,16 @@ describe("GlideClusterClient", () => { expect(await client.set(uuidv4(), uuidv4())).toEqual("OK"); expect(await client.dbsize()).toEqual(1); - expect(await client.flushdb(FlushMode.ASYNC)).toEqual("OK"); + expect(await client.flushdb({ mode: FlushMode.ASYNC })).toEqual( + "OK", + ); expect(await client.dbsize()).toEqual(0); expect(await client.set(uuidv4(), uuidv4())).toEqual("OK"); expect(await client.dbsize()).toEqual(1); - expect(await client.flushdb(FlushMode.SYNC)).toEqual("OK"); + expect(await client.flushdb({ mode: FlushMode.SYNC })).toEqual( + "OK", + ); expect(await client.dbsize()).toEqual(0); client.close(); @@ -1625,7 +1633,9 @@ describe("GlideClusterClient", () => { const key = uuidv4(); // setup: delete all keys - expect(await client.flushall(FlushMode.SYNC)).toEqual("OK"); + expect(await client.flushall({ mode: FlushMode.SYNC })).toEqual( + "OK", + ); // no keys exist so randomKey returns null expect(await client.randomKey()).toBeNull(); diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 97ae5107ba..0b247416a7 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -311,7 +311,9 @@ export function runBaseTests(config: { client instanceof GlideClient ? await client.info([InfoOptions.Commandstats]) : Object.values( - await client.info([InfoOptions.Commandstats]), + await client.info({ + sections: [InfoOptions.Commandstats], + }), ).join(); expect(oldResult).toContain("cmdstat_set"); expect(await client.configResetStat()).toEqual("OK"); @@ -320,7 +322,9 @@ export function runBaseTests(config: { client instanceof GlideClient ? await client.info([InfoOptions.Commandstats]) : Object.values( - await client.info([InfoOptions.Commandstats]), + await client.info({ + sections: [InfoOptions.Commandstats], + }), ).join(); expect(result).not.toContain("cmdstat_set"); }, protocol); @@ -339,9 +343,9 @@ export function runBaseTests(config: { expect(await client.lastsave()).toBeGreaterThan(yesterday); if (client instanceof GlideClusterClient) { - Object.values(await client.lastsave("allNodes")).forEach( - (v) => expect(v).toBeGreaterThan(yesterday), - ); + Object.values( + await client.lastsave({ route: "allNodes" }), + ).forEach((v) => expect(v).toBeGreaterThan(yesterday)); } const response = @@ -7785,11 +7789,14 @@ export function runBaseTests(config: { type: "primarySlotKey", key: key, }; - expect(await client.flushall(undefined, primaryRoute)).toBe( + expect(await client.flushall({ route: primaryRoute })).toBe( "OK", ); expect( - await client.flushall(FlushMode.ASYNC, primaryRoute), + await client.flushall({ + mode: FlushMode.ASYNC, + route: primaryRoute, + }), ).toBe("OK"); //Test FLUSHALL on replica (should fail) @@ -7799,7 +7806,7 @@ export function runBaseTests(config: { key: key2, }; await expect( - client.flushall(undefined, replicaRoute), + client.flushall({ route: replicaRoute }), ).rejects.toThrowError(); } }, protocol); @@ -7935,7 +7942,9 @@ export function runBaseTests(config: { type: "primarySlotKey", key: key, }; - expect(await client.dbsize(primaryRoute)).toBe(1); + expect(await client.dbsize({ route: primaryRoute })).toBe( + 1, + ); } }, protocol); },