-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
#1434 Added support for ZMSCORE new in Redis 6.2 RC #1437
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1437 +/- ##
==========================================
+ Coverage 85.90% 86.45% +0.55%
==========================================
Files 6 6
Lines 2894 2909 +15
==========================================
+ Hits 2486 2515 +29
+ Misses 408 394 -14
Continue to review full report at Codecov.
|
One comment: AFAICT, I think the new test introduced here never runs on CI because the base docker image for redis needs to bumped to something >= 6.2: https://github.com/andymccurdy/redis-py/blob/master/docker/base/Dockerfile#L1 The test is currently always skipped because |
Yes I see. So when I wrote the test, I removed the decorator and run it locally(tox) with version 6.2RC. |
This PR does that, it's merged in. Can you please re-sync with master, and then tests can run! Thank you again. |
redis/client.py
Outdated
If the member does not exist, a None will be returned | ||
in corresponding position. | ||
""" | ||
if not isinstance(members, list) or len(members) < 1: |
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 not isinstance(members, list) or len(members) < 1: | |
if not members: |
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.
So we should check if it's None or not and if it's a list type data?
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.
According to the zmscore docs ZMSCORE requires a minimum of one member. This either means that we either:
- Validate that there's a non-zero length list (as above).
- Validate that the item passed in is a string or a dictionary.
I'd rather we not overload the members argument, and instead always pass in a list. For the simple case, the list has one item (i.e ['foo']). Validating that we were passed a list I think is overkill, as the docs and the function signature are indicative of the requirement.
redis/client.py
Outdated
@@ -3281,6 +3287,22 @@ def zunionstore(self, dest, keys, aggregate=None): | |||
""" | |||
return self._zaggregate('ZUNIONSTORE', dest, keys, aggregate) | |||
|
|||
def zmscore(self, key, members): |
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.
def zmscore(self, key, members): | |
def zmscore(self, key, members=[]): |
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.
Sorry for the late reply.
I am ok with a default value proposal (for compatible reason). But not sure if using a mutable type is fine. This contains risk that the default value might be modified.
So maybe I should change it with a default value None and modify the function body accordingly?
Hi @2014BDuck thanks for your submission! Everything passes with the current unit tests. |
@chayim Hi sorry for the late reply. I would prefer using an immutable type as a default value, what do you think? |
I think members should merely be required, and we shouldn't do a check on
it. It should be a list. For what it's worth in the future I'm pretty pro
type hints, but we're not there.
…--c
|
@chayim OK then. I am going to add a list-type default value now. |
Ah sorry for the change. I am still thinking if we could just keep not using default value for the argument And we can stick with the same validation you suggested:
And, use empty list as default won't stop communicating with redis server when user pass, for example "asdfasdf" or a dict contain something. So the code is clean, same effect as we use empty list as default. |
For ZMSCORE, you have to have at a minimum one member
<https://redis.io/commands/zmscore>. and it's a list of members. We should
pass in a list, in order to not allow for overloadable constructs. A list
of length one, is still a list.
|
Yes it requires a minimum one member so we don't need a default value, as setting a So the only thing it can help is to tell user that it should be a list. However user can notice this requirement in the function doc. |
Two difference things are at play. The first is that yes - we should
document accordingly. Secondly, given that the only viable input is a
list, we should accept a list. If you want to validate the minimum length
of the list, to support the client use - I can support that! However, we
can't accept a default value of None, as the command doesn't support that.
|
Yes I see. So currently the default value is removed, which means user must pass
And with a Currently, this method can do:
Can't:
My point is, the default value won't affect any validation logic in the function body. No matter what default value we set, users can pass anything they want. So why not just don't set the default value and require an argument to be passed in. And we will have 2 different ways to handle the rest:
I think either way we don't need the default value. |
There are really only two cases present - the right items being specified, or not. The problem with validating the existence of a list, is that it doesn't prevent a user from passing in an invalid list - hence my being against that valiadation. Take as an example:
etc. In this example, True will always be accurate, as everything is a list. I can appreciate the isinstance check on a list, but I wouldn't do anything beyond that. The use will receive a ResponseError should they provide invalid input to redis. Were we to sanitize the inputs in this function, we'd be responsible for raising a DataError (or to be fair an AttributeError) exception in all cases. I'd rather allow redis to do what it does and surface accordingly. The following is a valid case, and I could understand generally doing this. However, I feel that type hints are a better answer.
|
OK, I am more clear about the responsibility of redis-py and redis server now. But I can't agree with using a mutable object as a default value. It's not recommended in any way and I never do this. Type hint could do this, but using So for the function signature part: Use And for the body part, I've removed the |
By the way, we have warnings for unresolved reference on the |
Hey @2014BDuck I'll take a look at the warning in another issue - or happily accept a PR. As always, thanks for this contribution, it's great to see! |
Pull Request check-list
Please make sure to review and check all of these items:
$ tox
pass with this change (including linting)?NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
Added support for zmscore command.
#1434
#1435