-
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
Changes from 4 commits
49af347
77eadf3
975a134
74f1a7c
234e7d0
1cbf7cd
1448f2c
4981719
9bc7507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -404,6 +404,11 @@ def parse_zscan(response, **options): | |||||
return int(cursor), list(zip(it, map(score_cast_func, it))) | ||||||
|
||||||
|
||||||
def parse_zmscore(response, **options): | ||||||
# zmscore: list of scores (double precision floating point number) or nil | ||||||
return [float(score) if score is not None else None for score in response] | ||||||
|
||||||
|
||||||
def parse_slowlog_get(response, **options): | ||||||
space = ' ' if options.get('decode_responses', False) else b' ' | ||||||
return [{ | ||||||
|
@@ -701,6 +706,7 @@ class Redis: | |||||
'XPENDING': parse_xpending, | ||||||
'ZADD': parse_zadd, | ||||||
'ZSCAN': parse_zscan, | ||||||
'ZMSCORE': parse_zmscore, | ||||||
} | ||||||
|
||||||
@classmethod | ||||||
|
@@ -3360,6 +3366,22 @@ def zunionstore(self, dest, keys, aggregate=None): | |||||
""" | ||||||
return self._zaggregate('ZUNIONSTORE', dest, keys, aggregate) | ||||||
|
||||||
def zmscore(self, key, members): | ||||||
""" | ||||||
Returns the scores associated with the specified members | ||||||
in the sorted set stored at key. | ||||||
|
||||||
``members`` should be a list of the member name. | ||||||
Return type is a list of score. | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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:
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. |
||||||
raise DataError('ZMSCORE members must be a non-empty list') | ||||||
pieces = [key] + members | ||||||
return self.execute_command('ZMSCORE', *pieces) | ||||||
|
||||||
def _zaggregate(self, command, dest, keys, aggregate=None, | ||||||
**options): | ||||||
pieces = [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.
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?