Skip to content

Commit

Permalink
fix commands.ts
Browse files Browse the repository at this point in the history
Signed-off-by: Chloe Yip <[email protected]>
  • Loading branch information
cyip10 committed Aug 9, 2024
1 parent 67e1eb5 commit 772356f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,10 @@ export function createHScan(
cursor: string,
options?: BaseScanOptions,
): command_request.Command {
const args: string[] = [key, cursor];
let args: string[] = [key, cursor];

if (options) {
if (options.match) {
args.push("MATCH", options.match);
}

if (options.count !== undefined) {
args.push("COUNT", options.count.toString());
}
args = args.concat(convertBaseScanOptionsToArgsArray(options));
}

return createCommand(RequestType.HScan, args);
Expand Down Expand Up @@ -3368,6 +3362,25 @@ export type BaseScanOptions = {
readonly count?: number;
};

/**
* @internal
*/
export function convertBaseScanOptionsToArgsArray(
options: BaseScanOptions,
): string[] {
const args: string[] = [];

if (options.match) {
args.push("MATCH", options.match);
}

if (options.count !== undefined) {
args.push("COUNT", options.count.toString());
}

return args;
}

/**
* @internal
*/
Expand All @@ -3376,16 +3389,10 @@ export function createZScan(
cursor: string,
options?: BaseScanOptions,
): command_request.Command {
const args: string[] = [key, cursor];
let args: string[] = [key, cursor];

if (options) {
if (options.match) {
args.push("MATCH", options.match);
}

if (options.count !== undefined) {
args.push("COUNT", options.count.toString());
}
args = args.concat(convertBaseScanOptionsToArgsArray(options));
}

return createCommand(RequestType.ZScan, args);
Expand Down

0 comments on commit 772356f

Please sign in to comment.