Skip to content

Commit

Permalink
Node: Add binary variant to generic commands. (valkey-io#2158)
Browse files Browse the repository at this point in the history
* Add binary variant to generic commands.

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored Aug 22, 2024
1 parent 860a646 commit 4c6ea2c
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 239 deletions.
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 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))
* 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
114 changes: 69 additions & 45 deletions node/src/BaseClient.ts

Large diffs are not rendered by default.

96 changes: 55 additions & 41 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 = {
/**
* 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 @@ -294,7 +303,7 @@ export function createInfo(options?: InfoOptions[]): command_request.Command {
/**
* @internal
*/
export function createDel(keys: string[]): command_request.Command {
export function createDel(keys: GlideString[]): command_request.Command {
return createCommand(RequestType.Del, keys);
}

Expand Down Expand Up @@ -1239,14 +1248,14 @@ export function createHVals(key: GlideString): command_request.Command {
/**
* @internal
*/
export function createExists(keys: string[]): command_request.Command {
export function createExists(keys: GlideString[]): command_request.Command {
return createCommand(RequestType.Exists, keys);
}

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

Expand Down Expand Up @@ -1275,11 +1284,11 @@ export enum ExpireOptions {
* @internal
*/
export function createExpire(
key: string,
key: GlideString,
seconds: number,
option?: ExpireOptions,
): command_request.Command {
const args: string[] =
const args =
option == undefined
? [key, seconds.toString()]
: [key, seconds.toString(), option];
Expand All @@ -1290,11 +1299,11 @@ export function createExpire(
* @internal
*/
export function createExpireAt(
key: string,
key: GlideString,
unixSeconds: number,
option?: ExpireOptions,
): command_request.Command {
const args: string[] =
const args =
option == undefined
? [key, unixSeconds.toString()]
: [key, unixSeconds.toString(), option];
Expand All @@ -1304,19 +1313,19 @@ export function createExpireAt(
/**
* @internal
*/
export function createExpireTime(key: string): command_request.Command {
export function createExpireTime(key: GlideString): command_request.Command {
return createCommand(RequestType.ExpireTime, [key]);
}

/**
* @internal
*/
export function createPExpire(
key: string,
key: GlideString,
milliseconds: number,
option?: ExpireOptions,
): command_request.Command {
const args: string[] =
const args =
option == undefined
? [key, milliseconds.toString()]
: [key, milliseconds.toString(), option];
Expand All @@ -1327,11 +1336,11 @@ export function createPExpire(
* @internal
*/
export function createPExpireAt(
key: string,
key: GlideString,
unixMilliseconds: number,
option?: ExpireOptions,
): command_request.Command {
const args: string[] =
const args =
option == undefined
? [key, unixMilliseconds.toString()]
: [key, unixMilliseconds.toString(), option];
Expand All @@ -1341,14 +1350,14 @@ export function createPExpireAt(
/**
* @internal
*/
export function createPExpireTime(key: string): command_request.Command {
export function createPExpireTime(key: GlideString): command_request.Command {
return createCommand(RequestType.PExpireTime, [key]);
}

/**
* @internal
*/
export function createTTL(key: string): command_request.Command {
export function createTTL(key: GlideString): command_request.Command {
return createCommand(RequestType.TTL, [key]);
}

Expand Down Expand Up @@ -1852,7 +1861,7 @@ export function createZRangeStore(
/**
* @internal
*/
export function createType(key: string): command_request.Command {
export function createType(key: GlideString): command_request.Command {
return createCommand(RequestType.Type, [key]);
}

Expand Down Expand Up @@ -1931,7 +1940,7 @@ export function createEcho(message: string): command_request.Command {
/**
* @internal
*/
export function createPTTL(key: string): command_request.Command {
export function createPTTL(key: GlideString): command_request.Command {
return createCommand(RequestType.PTTL, [key]);
}

Expand Down Expand Up @@ -1979,7 +1988,7 @@ export function createZRemRangeByScore(
}

/** @internal */
export function createPersist(key: string): command_request.Command {
export function createPersist(key: GlideString): command_request.Command {
return createCommand(RequestType.Persist, [key]);
}

Expand Down Expand Up @@ -2815,8 +2824,8 @@ export function createXGroupDestroy(
* @internal
*/
export function createRename(
key: string,
newKey: string,
key: GlideString,
newKey: GlideString,
): command_request.Command {
return createCommand(RequestType.Rename, [key, newKey]);
}
Expand All @@ -2825,8 +2834,8 @@ export function createRename(
* @internal
*/
export function createRenameNX(
key: string,
newKey: string,
key: GlideString,
newKey: GlideString,
): command_request.Command {
return createCommand(RequestType.RenameNX, [key, newKey]);
}
Expand Down Expand Up @@ -2862,28 +2871,34 @@ export function createPfMerge(
/**
* @internal
*/
export function createObjectEncoding(key: string): command_request.Command {
export function createObjectEncoding(
key: GlideString,
): command_request.Command {
return createCommand(RequestType.ObjectEncoding, [key]);
}

/**
* @internal
*/
export function createObjectFreq(key: string): command_request.Command {
export function createObjectFreq(key: GlideString): command_request.Command {
return createCommand(RequestType.ObjectFreq, [key]);
}

/**
* @internal
*/
export function createObjectIdletime(key: string): command_request.Command {
export function createObjectIdletime(
key: GlideString,
): command_request.Command {
return createCommand(RequestType.ObjectIdleTime, [key]);
}

/**
* @internal
*/
export function createObjectRefcount(key: string): command_request.Command {
export function createObjectRefcount(
key: GlideString,
): command_request.Command {
return createCommand(RequestType.ObjectRefCount, [key]);
}

Expand Down Expand Up @@ -2948,15 +2963,14 @@ export function createFlushDB(mode?: FlushMode): command_request.Command {
}

/**
*
* @internal
*/
export function createCopy(
source: string,
destination: string,
source: GlideString,
destination: GlideString,
options?: { destinationDB?: number; replace?: boolean },
): command_request.Command {
let args: string[] = [source, destination];
let args = [source, destination];

if (options) {
if (options.destinationDB !== undefined) {
Expand All @@ -2975,7 +2989,7 @@ export function createCopy(
* @internal
*/
export function createMove(
key: string,
key: GlideString,
dbIndex: number,
): command_request.Command {
return createCommand(RequestType.Move, [key, dbIndex.toString()]);
Expand Down Expand Up @@ -3502,7 +3516,7 @@ export type SortOptions = SortBaseOptions & {
* contains IDs of objects, `byPattern` can be used to sort these IDs based on an
* attribute of the objects, like their weights or timestamps.
*/
byPattern?: string;
byPattern?: GlideString;

/**
* A pattern used to retrieve external keys' values, instead of the elements at `key`.
Expand All @@ -3517,7 +3531,7 @@ export type SortOptions = SortBaseOptions & {
* be used to include the actual element from `key` being sorted. If not provided, only
* the sorted elements themselves are returned.
*/
getPatterns?: string[];
getPatterns?: GlideString[];
};

type SortBaseOptions = {
Expand Down Expand Up @@ -3558,16 +3572,16 @@ export type Limit = {

/** @internal */
export function createSort(
key: string,
key: GlideString,
options?: SortOptions,
destination?: string,
destination?: GlideString,
): command_request.Command {
return createSortImpl(RequestType.Sort, key, options, destination);
}

/** @internal */
export function createSortReadOnly(
key: string,
key: GlideString,
options?: SortOptions,
): command_request.Command {
return createSortImpl(RequestType.SortReadOnly, key, options);
Expand All @@ -3576,11 +3590,11 @@ export function createSortReadOnly(
/** @internal */
function createSortImpl(
cmd: RequestType,
key: string,
key: GlideString,
options?: SortOptions,
destination?: string,
destination?: GlideString,
): command_request.Command {
const args: string[] = [key];
const args = [key];

if (options) {
if (options.limit) {
Expand Down Expand Up @@ -3705,7 +3719,7 @@ export function createLCS(
/**
* @internal
*/
export function createTouch(keys: string[]): command_request.Command {
export function createTouch(keys: GlideString[]): command_request.Command {
return createCommand(RequestType.Touch, keys);
}

Expand Down
Loading

0 comments on commit 4c6ea2c

Please sign in to comment.