-
Notifications
You must be signed in to change notification settings - Fork 69
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
Implemented IFEQ set command in python with tests #2962
Conversation
I'm open to suggestions, critique, and potential variable name changes. |
@@ -73,10 +73,12 @@ class ConditionalChange(Enum): | |||
A condition to the `SET`, `ZADD` and `GEOADD` commands. | |||
- ONLY_IF_EXISTS - Only update key / elements that already exist. Equivalent to `XX` in the Valkey API. | |||
- ONLY_IF_DOES_NOT_EXIST - Only set key / add elements that does not already exist. Equivalent to `NX` in the Valkey API. | |||
- ONLY_IF_EQUAL - Only update key if the provided value is equal to the old value. Equivalent to `IFEQ` in the Valkey API. |
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.
It is a bit of a problem, since this type is optional in ZADD
and GEOADD
as well, and we can't let IFEQ
part of it.
We need to plan it a bit different, but I want to make sure first if there are any plans to add it to the other in the future so we can take a smart decision of how to handle it.
Let's keep working on the PR, but keep in mind that we are going to make changes here, it will need to be a separate type. Ill tag on the discussion in Valkey WS, and we will discuss it offline to understand it better.
In addition, while the others are not requiring extra parameter, IFEQ
, and we do not want to allow users mistakenly adding one of the parameters and the other and fail on run time, and we want to enforce to the best we can do, the right usage of the type, more like we do in the ExpiryType
than as we do it in ConditionalChange
, but let's wait for response from community, and then lets plan it better.
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.
To whom come across - the solution we decided to go on is a Union between ConditionalChange
and a new class OnlyIfEqual
which will include comparison_value
as a field.
The reason not to create a separate SetConditionalChange
Enum to use a Union between the two, is that Enum doesn't enforce using comparison_value
along with OnlyIfEqual
and will end up as a runtime error, while can be avoided with type checking when it is a class.
The reason that the class is OnlyIfEqual
and not more generic is because to make it more generic we need to avoid setting specific required fields, and that's miss the logic in trying to enforce comparison_value
.
f1ae208
to
9250c5f
Compare
It would appear that I added one commit too many to the PR. It won't change anything (it was just my typo fixes from my last PR) but it's a little redundant. |
|
||
elif isinstance(conditional_set, OnlyIfEqual): | ||
args.append("IFEQ") | ||
if conditional_set.comparison_value: |
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.
Since we added the parameter to be a Class with a field this if
is not relevant anymore, the class has to have this field.
@dataclass | ||
class OnlyIfEqual(): | ||
""" | ||
Condition to the `SET` command |
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.
Condition to the `SET` command | |
Change condition to the `SET` command, | |
For additional conditonal options see ConditionalChange |
Test fails since you created a new type, hence needs to be imported to https://github.com/valkey-io/valkey-glide/blob/main/python/python/glide/__init__.py to be available for users. |
Please fix linting failures |
The formatter reformatted the way I call the SET command to a way that isn't consistent with the rest of the test files. |
Please give more details |
All of the times SET is called, they format it like |
ok GitHub did not format that the way I hoped. Basically the formatter put new lines between every parameter despite that not happening in the rest of the test cases |
63f6f7d
to
87520fe
Compare
…for IFEQ Signed-off-by: Angraybill <[email protected]>
Signed-off-by: Angraybill <[email protected]>
Signed-off-by: Angraybill <[email protected]>
Signed-off-by: Angraybill <[email protected]>
b7bd358
to
b223110
Compare
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 work! Even after the surprising challenges, it looks good, clean code, good docs, and extra fixes. Approved.
* Define new function, change paramter type to Union, add conditionals for IFEQ Signed-off-by: Angraybill <[email protected]> * Tests for IFEQ, positive and negative cases Signed-off-by: Angraybill <[email protected]> * Update Changelog Signed-off-by: Angraybill <[email protected]> * Import OnlyIfEqual in init file Signed-off-by: Angraybill <[email protected]> --------- Signed-off-by: Angraybill <[email protected]>
* Define new function, change paramter type to Union, add conditionals for IFEQ Signed-off-by: Angraybill <[email protected]> * Tests for IFEQ, positive and negative cases Signed-off-by: Angraybill <[email protected]> * Update Changelog Signed-off-by: Angraybill <[email protected]> * Import OnlyIfEqual in init file Signed-off-by: Angraybill <[email protected]> --------- Signed-off-by: Angraybill <[email protected]>
* Define new function, change paramter type to Union, add conditionals for IFEQ Signed-off-by: Angraybill <[email protected]> * Tests for IFEQ, positive and negative cases Signed-off-by: Angraybill <[email protected]> * Update Changelog Signed-off-by: Angraybill <[email protected]> * Import OnlyIfEqual in init file Signed-off-by: Angraybill <[email protected]> --------- Signed-off-by: Angraybill <[email protected]>
* Define new function, change paramter type to Union, add conditionals for IFEQ Signed-off-by: Angraybill <[email protected]> * Tests for IFEQ, positive and negative cases Signed-off-by: Angraybill <[email protected]> * Update Changelog Signed-off-by: Angraybill <[email protected]> * Import OnlyIfEqual in init file Signed-off-by: Angraybill <[email protected]> --------- Signed-off-by: Angraybill <[email protected]>
Implements the
IFEQ
option into theSET
command. Tests were added on test_async_client.py.Issue link
This Pull Request is linked to issue (URL): #2811
Checklist
Before submitting the PR make sure the following are checked: