Skip to content

Node: added zrange and zrangeWithScores commands. - #1115

Merged
shohamazon merged 4 commits into
valkey-io:mainfrom
adanWattad:node/zrange
Apr 10, 2024
Merged

shohamazon merged 4 commits into
valkey-io:mainfrom
adanWattad:node/zrange

Conversation

@adanWattad

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@adanWattad
adanWattad requested a review from a team as a code owner March 13, 2024 15:15
@adanWattad
adanWattad force-pushed the node/zrange branch 2 times, most recently from 47e00a5 to 71af8de Compare March 13, 2024 15:21
Comment thread node/src/Commands.ts Outdated

@barshaul barshaul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why RangeByScoreOrLex isn't separated to two types as we do in python, RangeByScore and RangeByLex? we shouldn't accept ScoreLimit as strings when is lex is false, and we should except number when is lex is true. We also cannot use it later on with the specific zrange functions (e.g. ZRANGEBYLEX). Please follow python's design, and ping me when it's ready for review 🙏

Comment thread node/src/BaseClient.ts Outdated
Comment thread node/src/BaseClient.ts Outdated
Comment thread node/src/BaseClient.ts
Comment thread node/src/BaseClient.ts
Comment thread node/src/Commands.ts Outdated
*/
type Range<T> = {
/**
* The start score boundary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same - it should be used both for lex and score, so the doc might be confusing

Comment thread node/src/Commands.ts Outdated
Comment thread node/src/Commands.ts Outdated
};
};

export type RangeByScore = Range<number> & { type: "byScore" };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice solution

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think "Lex" and "Score" is sufficient for 'type'

@barshaul barshaul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

round

@adanWattad

Copy link
Copy Markdown
Contributor Author

@barshaul ready

@acarbonetto acarbonetto added the node 🐢 Node.js wrapper label Mar 21, 2024
Comment thread node/src/BaseClient.ts Outdated
* If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
*
* @example
* await client.zadd("mySortedSet", \{ member1: 1.0, member2: 2.0, member3: 3.0 \});

@barshaul barshaul Apr 2, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please follow format for examples:

* @example
 * ```typescript
 * // Example usage of the echo method
 * const echoedMessage = await client.echo("Glide-for-Redis");
 * console.log(echoedMessage); // Output: "Glide-for-Redis"
 * ```
 */

Comment thread node/src/BaseClient.ts Outdated
* @example
* await client.zadd("mySortedSet", \{ member1: 1.0, member2: 2.0, member3: 3.0 \});
*
* await client.zrange("mySortedSet", \{ start: 0, stop: -1 \});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why are the \ needed?

Comment thread node/src/Commands.ts Outdated
export type RangeByScore = SortedSetRange<number> & { type: "byScore" };
export type RangeByLex = SortedSetRange<string> & { type: "byLex" };

function getScoreLimitArg(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

getScoreBoundaryArg

Comment thread node/src/Commands.ts

function getScoreLimitArg(
score: ScoreBoundary<number> | ScoreBoundary<string>,
isLex: boolean = false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add documentation, this function isn't trivial

@barshaul barshaul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fix& mrege

@shohamazon
shohamazon merged commit 4e7acdc into valkey-io:main Apr 10, 2024
cyip10 pushed a commit to Bit-Quill/valkey-glide that referenced this pull request Jun 24, 2024
---------

Co-authored-by: Adan <adanwat@amazon.com>
Co-authored-by: Shoham Elias <shohame@amazon.com>
Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
affonsov pushed a commit that referenced this pull request Aug 21, 2026
---------

Co-authored-by: Adan <adanwat@amazon.com>
Co-authored-by: Shoham Elias <shohame@amazon.com>
Co-authored-by: Shoham Elias <116083498+shohamazon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

node 🐢 Node.js wrapper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants