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

Feat: implement new command EXZRANDMEMBER. #6

Merged
merged 3 commits into from
Jun 20, 2022
Merged

Feat: implement new command EXZRANDMEMBER. #6

merged 3 commits into from
Jun 20, 2022

Conversation

RinChanNOWWW
Copy link
Contributor

@RinChanNOWWW RinChanNOWWW commented Jun 19, 2022

Signed-off-by: RinChanNOWWW hzy427@gmail.com

Summary

related issues: #4

Implementation reference: Redis 6.2 https://redis.io/commands/zrandmember/

Command Description

EXZRANDMEMBER

EXZRANDMEMBER key [ count [WITHSCORES]]
time complexity:O(N) where N is the number of elements returned.

Command Description:

When called with just the key argument, return a random element from the sorted set value stored at key.

If the provided count argument is positive, return an array of distinct elements. The array's length is either count or the sorted set's cardinality (EXZCARD), whichever is lower.

If called with a negative count, the behavior changes and the command is allowed to return the same element multiple times. In this case, the number of returned elements is the absolute value of the specified count.

The optional WITHSCORES modifier changes the reply so it includes the respective scores of the randomly selected elements from the sorted set.

Return value

Bulk string reply: without the additional count argument, the command returns a Bulk Reply with the randomly selected element, or nil when key does not exist.

Array reply: when the additional count argument is passed, the command returns an array of elements, or an empty array when key does not exist. If the WITHSCORES modifier is used, the reply is a list elements and their scores from the sorted set.

TODO

  • Fixing the compatibility problems with Redis 5.0 and 6.0.

Signed-off-by: RinChanNOWWW <hzy427@gmail.com>
@RinChanNOWWW RinChanNOWWW marked this pull request as draft June 19, 2022 05:40
@RinChanNOWWW RinChanNOWWW changed the title Feat: implement new command EXZRANDMEMBER. [WIP] Feat: implement new command EXZRANDMEMBER. Jun 19, 2022
@RinChanNOWWW RinChanNOWWW changed the title [WIP] Feat: implement new command EXZRANDMEMBER. Feat: implement new command EXZRANDMEMBER. Jun 19, 2022
@RinChanNOWWW RinChanNOWWW marked this pull request as ready for review June 19, 2022 05:52
Signed-off-by: RinChanNOWWW <hzy427@gmail.com>
src/tairzset.c Show resolved Hide resolved
Signed-off-by: RinChanNOWWW <hzy427@gmail.com>
@chenyang8094 chenyang8094 merged commit 5c1ce27 into tair-opensource:master Jun 20, 2022
@RinChanNOWWW RinChanNOWWW deleted the FEAT-EXZRANDMEMBER branch June 20, 2022 11:49
@chenyang8094
Copy link
Collaborator

LGTM

@chenyang8094 chenyang8094 added the to-be-merged to be merged label Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-be-merged to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants