Skip to content

ZRANK ability to return "unique" rank #943

Open

Description

@antirez

There are applications where it is useful to get the rank without counting all the duplicated entries with the same score, for instance in a game leader board if I've the best score, even if there are other three with the same score, I'm supposed to be the first.

The feature was already implemented here:

https://github.com/Sylvain-Royer/redis/tree/unique_ties

It was also discussed in the mailing list. The new function is quite useful and the code not too complex, so I'll re-evaluate it at some time in the future as the code gets more tested.

Activity

  1. ghost assigned on Feb 12, 2013
  2. antirez commented on Jul 17, 2013

    @antirez
    ContributorAuthor

    I'm sorry to move that to 3.0, not enough time for a serious review for 2.8.

  3. venky1 commented on Sep 18, 2014

    @venky1

    Is this available as part of 3.0 beta.

  4. mattsta commented on Sep 18, 2014

    @mattsta
    Contributor

    Nope, not in 3.0 yet.

    I've extracted the functionality from https://github.com/Sylvain-Royer/redis/commits/unique_ties and we can track it in PR #2011

  5. added a commit that references this issue on Oct 9, 2014
    08d38d2
  6. added a commit that references this issue on Dec 11, 2014
    9605949
  7. adamscherer commented on Jun 22, 2015

    @adamscherer

    Any guidance on whether this will make the 3.2 release?

  8. doncorsean-private commented on Jul 22, 2015

    @doncorsean-private

    I could use this as well (fingers crossed).

  9. a-chernykh commented on Aug 24, 2015

    @a-chernykh

    I am looking forward for this to be merged. We need leaderboards with ties in our app.

  10. doncorsean-private commented on Aug 27, 2015

    @doncorsean-private

    I just built it from source ;) AWS doesn't deploy a recent version in elasticache anyhow

  11. swinbank commented on Mar 5, 2016

    @swinbank

    Looking forward to this. Should ZCOUNT receive this treatment, too?

  12. AlainPilon commented on Aug 8, 2016

    @AlainPilon

    +1 on this.

  13. henryren commented on Oct 30, 2016

    @henryren

    +1 on this.

  14. 5 remaining items

  15. prettybot commented on Nov 8, 2018

    @prettybot

    Please add this feature. It will be quite useful.

  16. krishnaff commented on Feb 18, 2019

    @krishnaff

    The original feature request and PR were in 2013.
    Its 2019. Still waiting for this... :(

  17. kpfecteau commented on May 10, 2020

    @kpfecteau

    I know this is pretty old, but any chance this ever gets accepted into the current version?

  18. rookie7799 commented on Aug 10, 2020

    @rookie7799

    Nothing?

  19. HADB commented on Sep 16, 2021

    @HADB

    Any updates?

  20. added
    state:help-wanted
    and removed on Sep 16, 2021
  21. removed this from the Redis >= 4.2 milestone on Sep 16, 2021
  22. madolson commented on Sep 16, 2021

    @madolson
    Contributor

    This seems pretty straight forward, I think someone just needs to go implement it.

  23. kshitijjolly-probo commented on Sep 24, 2021

    @kshitijjolly-probo

    +1

    I think we can do a workaround for this using ZSCORE and ZCOUNT function as follows:

    1. Get the score for the sorted set entry using ZSCORE function - let suppose 12.5
    2. Get the count of entries having lesser score than the entry using ZCOUNT function - ZCOUNT myset -inf (12.5
  24. DuncanHouston commented on Jun 9, 2022

    @DuncanHouston

    +1

    I think we can do a workaround for this using ZSCORE and ZCOUNT function as follows:

    1. Get the score for the sorted set entry using ZSCORE function - let suppose 12.5
    2. Get the count of entries having lesser score than the entry using ZCOUNT function - ZCOUNT myset -inf (12.5

    I've just implemented a solution, and this forms part of it. It's not really that hard. I wanted to show the current user on the leaderboard (if you're just showing say top 10, it's even easier).

    So, if the current user is in the top 5, fetch the top 10.
    Else, fetch top 3, and then 2 above user, user, and 4 below.

    I fetch (in a multi):

    1. the user's rank (zRevRank)
    2. the user's score (zScore, pity you can't do both at once)

    Then I fetch the 10 entries described above

    Then I fetch the number of entries with a higher score than the user (zCount)
    Then I have an algorithm to update the positions depending if I have the top 10, or the 2 disjoint sets (1-3, and n-2 to n+4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

class:featurestate:help-wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions