Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SET IFEQ command implemented in node + tests #2909

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Maayanshani25
Copy link
Collaborator

Issue link

This Pull Request is linked to issue (URL): [/issues/2811]

Description

This pull Request is implemented the IFEQ option in the SET commamnd. Tests were added to the shared tests, and docstring to the command and the related methods and structures.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@Maayanshani25 Maayanshani25 requested a review from a team as a code owner January 1, 2025 10:38
Maayan Shani and others added 2 commits January 1, 2025 10:41
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Please add a changelog

@@ -1473,7 +1473,7 @@ export class BaseClient {
* @param value - The value to store with the given key.
* @param options - (Optional) See {@link SetOptions} and {@link DecoderOption}.
* @returns - If the value is successfully set, return OK.
* If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` conditions, return null.
* If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` or `onlyIfEqual`conditions, return null.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` or `onlyIfEqual`conditions, return null.
* If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` or `onlyIfEqual` conditions, return `null`.

* it already exist. Equivalent to `EX` in the Valkey API. if `conditional` is
* not set the value will be set regardless of prior value existence. If value
* isn't set because of the condition, return null.
* it already exist. Equivalent to `EX` in the Valkey API. `onlyIfEqual` - Only set the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* it already exist. Equivalent to `EX` in the Valkey API. `onlyIfEqual` - Only set the
* it already exists. Equivalent to `EX` in the Valkey API. `onlyIfEqual` - Only set the

} else if (options.conditionalSet === "onlyIfEqual") {
args.push("IFEQ");

if (options.comparisonValue != undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (options.comparisonValue != undefined) {
if (options.comparisonValue) {

conditionalSet?: "onlyIfExists" | "onlyIfDoesNotExist";
conditionalSet?: "onlyIfExists" | "onlyIfDoesNotExist" | "onlyIfEqual";
/**
* If onlyIfEqual is set, the value to compare the existing value with.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* If onlyIfEqual is set, the value to compare the existing value with.
* If `onlyIfEqual` is set, the value to compare the existing value with.

Comment on lines +133 to +134
* if `conditional` is not set the value will be set regardless of prior value existence.
* If value isn't set because of the condition, return null.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I propose to add line breaks for better readability.

onlyIfDoesNotExist - ...
onlyIfExists - ...

And move last two lines to set docs.

/**
* If onlyIfEqual is set, the value to compare the existing value with.
*/
comparisonValue?: GlideString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do

SetOptions = ({
conditionalSet?: "onlyIfExists" | "onlyIfDoesNotExist";
} | {
conditionalSet: "onlyIfEqual";
comparisonValue: GlideString;
} & {
...
}
)

and then remove value check on lines 179-184

@@ -8260,18 +8319,55 @@ export function runBaseTests(config: {

expect(setRes).toBeDefined();
}

// onlyIfEqual tests
if (!cluster.checkIfServerVersionLessThan("8.1.0")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You already have a version check on line 8365. This one is always true.

@Yury-Fridlyand Yury-Fridlyand added the node Node.js wrapper label Jan 2, 2025
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.

2 participants