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

Add noscores option to command ZSCAN. #324

Merged
merged 5 commits into from May 7, 2024

Conversation

CharlesChen888
Copy link
Member

@CharlesChen888 CharlesChen888 commented Apr 16, 2024

Command syntax is now:

ZSCAN key cursor [MATCH pattern] [COUNT count] [NOSCORES]

Return format:

127.0.0.1:6379> zadd z 1 a 2 b 3 c
(integer) 3
127.0.0.1:6379> zscan z 0
1) "0"
2) 1) "a"
   2) "1"
   3) "b"
   4) "2"
   5) "c"
   6) "3"
127.0.0.1:6379> zscan z 0 noscores
1) "0"
2) 1) "a"
   2) "b"
   3) "c"

when NOSCORES is on, the command will only return members in the zset, without scores.

For client side parsing the command return, I believe it is fine as long as the command is backwards compatible. The return structure are still lists, what has changed is the content. And clients can tell the difference by the subcommand they use.

Since novalues option of HSCAN is already accepted (redis/redis#12765), I think similar thing can be done to ZSCAN.

Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
@zuiderkwast
Copy link
Contributor

zuiderkwast commented Apr 16, 2024

I suggested this command. Nobody asked for it, but it seems like a logical thing to add together with HSCAN NOVALUES.

@valkey-io/core-team Let's have a vote on this new argument. Give your 👍 or 👎 please.

@madolson
Copy link
Member

I was pretty strongly against this command because I don't want to add commands that aren't solving a problem. HSCAN without values made more sense, because values can be large, but here the values are just decimals which can never be that expensive.

@CharlesChen888
Copy link
Member Author

Whether values are expensive to return to client is a relative thing. If the sds length of scores and members are in the same order of magnitude (in which case, names of members are short), we can certainly save considerable traffic by using noscores. Sometimes in situations with heavy network load, we try to save as much as we can.

@enjoy-binbin
Copy link
Member

I see it was rejected in the previous redis core-team. i agree with madolson that we should not add commands that aren't solving a problem. But on the other hands, although it may not solve many problems, it seem it does will slove some problems (like CharlesChen888's case). Another thing is that it is symmetrical will HSCAN novalues. (i am a guy prefer symmetrical)

@soloestoy
Copy link
Member

IMHO, ZSCAN and HSCAN have no much differences, and I prefer keeping symmetry : )

@zuiderkwast
Copy link
Contributor

@CharlesChen888 please don't vote when it's a core team vote (AKA technical steering committee). We're trying to be transparent and do voting in the open.

Feel free to do other emojis and to thumbs up or down on other comments.

@madolson
Copy link
Member

madolson commented Apr 17, 2024

it seem it does will slove some problems (like CharlesChen888's case).

I would just like to clarify this isn't solving any known problem, it's a solution (reducing usage) to an imagined problem. I was asking for a use case where you would want to incrementally scan a semi-large sorted set and only care about the field names (and not care about order I suppose). Ideally we would be able to articulate "why" a user would want to use this command.

Another reason the old team was against is that this can already be solved by ZRANGE (which by default doesn't include scores). A valid counter point here is that ZSCAN is more efficient, since we are skipping the O(Log(N)) seek at the start of each ZRANGE, but we haven't seen folks materially complain about that.

IMHO, ZSCAN and HSCAN have no much differences, and I prefer keeping symmetry : )

I still don't really think symmetry is a needed or useful property for Valkey. We can make the same argument about a lot of other commands, like why doesn't INCR support XX (Increment only if the key is there). I don't want this to get bogged down into whether that is useful, because the suggestion was that it was important to have symmetry. Ideally we would come up with some tenets to make these types of decisions easier.

I don't specifically care about this command that strongly, I just don't want this to be the start of adding a bunch of more commands for "symmetry".

@soloestoy
Copy link
Member

Perhaps "symmetry" wasn't the most precise term, using the "same type" might be a more fitting description.

The topic of whether user demand should precede the implementation of commands, or vice versa, is quite interesting. In this case, I lean towards implementing the command first. My intuition tells me that upon seeing hscan novalue, users of zscan or zrange would naturally think of zscan noscore.

@PingXie
Copy link
Member

PingXie commented Apr 18, 2024

What is the end to end use case here? This proposal seems to suggest that there is a need to retrieve just the members of the sorted set, unordered. What would an application do with this information?

As far as general guidelines are concerned, I agree that we should not get ahead of ourselves too much and "predict" use cases, especially in the user facing interface areas. It is a slippery slope.

@CharlesChen888
Copy link
Member Author

CharlesChen888 commented Apr 19, 2024

What is the end to end use case here? This proposal seems to suggest that there is a need to retrieve just the members of the sorted set, unordered. What would an application do with this information?

Perhaps sending messages to all players on a ranking list (which is one of the most common use cases for zset), and the list is too long for a single ZRANGE.

@madolson
Copy link
Member

Perhaps sending messages to all players on a ranking list (which is one of the most common use cases for zset), and the list is too long for a single ZRANGE.

You can incrementally scan through a sorted set with ZRANGE though. It has different properties of the SCAN though, since it wouldn't guarantee at least once delivery I suppose, since the scores could change.

@hwware
Copy link
Member

hwware commented Apr 24, 2024

I have no objecttion to add this option. Becuase according to the SCAN, SSCAN, HSCAN and ZSCAN doc (https://redis.io/docs/latest/commands/scan/) , the return value is a two element multi-bulk reply, where the first element is a string representing an unsigned 64 bit number (the cursor), and the second element is a multi-bulk with an array of elements.

For the ZSCAN, if option NOSCORES is added, only the member value as an array is returned, without their scores. It could make the client codes much easiter.

@madolson
Copy link
Member

madolson commented May 3, 2024

@hwware and @PingXie Your two votes are missing btw. Do you want to be explicit and add it to viktors comment.

@PingXie
Copy link
Member

PingXie commented May 6, 2024

@hwware and @PingXie Your two votes are missing btw. Do you want to be explicit and add it to viktors comment

Voted.

Copy link
Member

@PingXie PingXie left a comment

Choose a reason for hiding this comment

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

can you add a history section to zscan.json as well for this new noscores option?

Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
@soloestoy soloestoy added major-decision-approved Approved by core team and removed major-decision-pending Needs decision by core team labels May 6, 2024
Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (unstable@2ec8f63). Click here to learn what that means.

Additional details and impacted files
@@             Coverage Diff             @@
##             unstable     #324   +/-   ##
===========================================
  Coverage            ?   68.43%           
===========================================
  Files               ?      109           
  Lines               ?    61689           
  Branches            ?        0           
===========================================
  Hits                ?    42215           
  Misses              ?    19474           
  Partials            ?        0           
Files Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/db.c 87.39% <87.50%> (ø)

Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

LGTM

@madolson madolson added the needs-doc-pr This change needs to update a documentation page label May 6, 2024
@madolson
Copy link
Member

madolson commented May 6, 2024

Still missing a doc PR, but other than that also LGTM.

@hwware
Copy link
Member

hwware commented May 6, 2024

@hwware and @PingXie Your two votes are missing btw. Do you want to be explicit and add it to viktors comment.

Voted, no objection for this.

@enjoy-binbin enjoy-binbin added the release-notes This issue should get a line item in the release notes label May 7, 2024
@zuiderkwast
Copy link
Contributor

OK, this is ready to merge. @CharlesChen888 Do you have a doc PR for this?

@CharlesChen888
Copy link
Member Author

@zuiderkwast doc PR is ready.

@soloestoy soloestoy merged commit ba9dd7b into valkey-io:unstable May 7, 2024
18 checks passed
soloestoy pushed a commit to valkey-io/valkey-doc that referenced this pull request May 7, 2024
Doc PR for valkey-io/valkey#324

Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
arthurkiller pushed a commit to arthurkiller/valkey that referenced this pull request May 7, 2024
Command syntax is now:
```
ZSCAN key cursor [MATCH pattern] [COUNT count] [NOSCORES]
```
Return format:
```
127.0.0.1:6379> zadd z 1 a 2 b 3 c
(integer) 3
127.0.0.1:6379> zscan z 0
1) "0"
2) 1) "a"
   2) "1"
   3) "b"
   4) "2"
   5) "c"
   6) "3"
127.0.0.1:6379> zscan z 0 noscores
1) "0"
2) 1) "a"
   2) "b"
   3) "c"
```
when NOSCORES is on, the command will only return members in the zset,
without scores.

For client side parsing the command return, I believe it is fine as long
as the command is backwards compatible. The return structure are still
lists, what has changed is the content. And clients can tell the
difference by the subcommand they use.

Since `novalues` option of `HSCAN` is already accepted
(redis/redis#12765), I think similar thing can be done to `ZSCAN`.

---------

Signed-off-by: Chen Tianjie <TJ_Chen@outlook.com>
@madolson madolson removed the needs-doc-pr This change needs to update a documentation page label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-decision-approved Approved by core team release-notes This issue should get a line item in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants