-
Notifications
You must be signed in to change notification settings - Fork 76
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
Node: Enable +/-inf as score for ZADD #3370
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update zadd
in transaction too
Add changelog
node/src/BaseClient.ts
Outdated
membersAndScores: SortedSetDataType | Record<string, number>, | ||
membersAndScores: | ||
| SortedSetDataType | ||
| Record<string, number> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Record<string, number> |
I think you can remove this line, because InfScore
already includes a number
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking further I think you can update SortedSetDataType
export type SortedSetDataType = {
/** The sorted set element name. */
element: GlideString;
/** The element score. */
score: InfScore;
}[];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SortedSetDataType
is used as the return type of many sorted set commands. Changing it will be too much of an impact, not to mention we are avoiding a "breaking change" here.
Same concern resulting me not removing | Record<string, number>
, but I'm not entirely sure if removing it would count as a "breaking change". Please advise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right.
Before suggesting other destructive ideas, could you please try ZADD
with Number.POSITIVE_INFINITY
and Number.NEGATIVE_INFINITY
?
Probably we just should add extra handling and convert those to +-inf
? No type changes needed at all in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.POSITIVE_INFINITY
and Number.NEGATIVE_INFINITY
works with existing API, no change needed. Have suggested the same as workaround, but I don't think we can use that as a reason to not do this fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the standard of non-breaking change is that existing downstream code still works, I think we can go ahead and modify both the object type (SortedSetDataType
-> ElementAndScore
) as well as the Record type (Record<string, number>
-> Record<string, Score>
). User will be able to feed +inf
and -inf
using either of the formats. I've tested and all existing tests passed after the change. Will update the PR for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'm not sure what the standard is, i can check it.
To my understanding it means breaking. Like literally breaking.
If nothing is going to happen to the user code, and he can keep running the same code, it's not breaking anything.
I'll ask Google to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Have updated the PR accordingly. Please review again 🙏
110feb8
to
3b84886
Compare
577ea21
to
4e688b7
Compare
84ec8fa
to
657ff88
Compare
64f0d0e
to
42afc15
Compare
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
Signed-off-by: James Xin <[email protected]>
42afc15
to
506995c
Compare
element: GlideString; | ||
/** The element score. */ | ||
score: Score; | ||
}[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avifenesh I followed how SortedSetDataType
is defined as an array, instead of your approach of adding | ElementAndScore[]
towards the end. I understand that | ElementAndScore[]
gives user more flexibility, as they could feed either an array or a single object. However, I feel like this is deviated from the main purpose of this PR.
Please comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ElementAndScore
is always an array
?
I find it very limiting.
I would prefer
export type ElementAndScore = {
/** The sorted set element name. */
element: GlideString;
/** The element score. */
score: Score;
};
And
public async zadd(
key: GlideString,
membersAndScores: ElementAndScore | ElementAndScore[] | Record<string, Score>,
options?: ZAddOptions,
):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or does the non Array version is not relevant?
If so,
public async zadd( key: GlideString, membersAndScores: ElementAndScore[] | Record<string, Score>, options?: ZAddOptions, ):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if still array so at least ElementsAndScores
since it is not a singular. But I would really prefer an array of custom type, then costume type which is an array of unnamed object, with another type in it.
Array is a real type, unnamed object is the one I would give the customization to, and it will be more dynamic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree that giving a name to an object makes more sense than to an array of it. Also, this is another example of using the same type on multiple commands, especially when it's an input-output crossover, being very problematic, as the output (return value) will always be an array, but not necessarily the input.
My actual concern on accepting ElementAndScore
as a single object is, under corner cases, it creates ambiguity, as we don't know if user is passing a single ElementAndScore
object, or a Record<string, Score>
. Consider below example:
const ambiguousMembersAndScores = {
element: "+inf",
score: 42,
};
This could be interpreted as:
- A single member-score pair, with
"+inf"
being the member, and42
being the score. - Two member-score pairs, with the first member being
"element"
, first score being+inf
, and the second member being"score"
, and second score being42
.
Maybe we can get away with this ambiguity with some cleaver if-else condition in createZAdd()
, but I'm not sure if it's worth it.
If you agree with me on this, I'll just change the definition of ElementAndScore
to non-array, single object, and use ElementAndScore[] | Record<string, Score>
as the type of membersAndScores
on ZADD, so for both types in this union type, it is a one-to-one substitution (SortedSetDataType
-> ElementAndScore[]
, Record<string, number>
-> Record<string, Score>
), potentially easier for user to understand, as we are pulling off this type change on a minor version (1.4), and trying not to make it a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the last. Our goal is to remove Record<string, Score>
later, right?
You can mark it as @dperecated
in the docs above, so users will see. Never tried it, so just if it is not extremely complicated. Otherwise, add a note in which users should use the ElementAndScore
and avoid Record<string, Score>
as it going to be deprecated.
Signed-off-by: James Xin <[email protected]>
Issue link
This Pull Request is linked to issue (URL): #3360
Checklist
Before submitting the PR make sure the following are checked: