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.
Comment From: antirez
I'm sorry to move that to 3.0, not enough time for a serious review for 2.8.
Comment From: venky1
Is this available as part of 3.0 beta.
Comment From: mattsta
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
Comment From: adamscherer
Any guidance on whether this will make the 3.2 release?
Comment From: doncorsean
I could use this as well (fingers crossed).
Comment From: a-chernykh
I am looking forward for this to be merged. We need leaderboards with ties in our app.
Comment From: doncorsean
I just built it from source ;) AWS doesn't deploy a recent version in elasticache anyhow
Comment From: swinbank
Looking forward to this. Should ZCOUNT receive this treatment, too?
Comment From: AlainPilon
+1 on this.
Comment From: henryren
+1 on this.
Comment From: emerak
Please do so
Comment From: jgkim999
+1 on this.
Comment From: hyunilmmt
+1
Comment From: ankitrex
+1 It'll be useful
Comment From: itamarhaber
@antirez I also think this would be a nice addition to the core - if you agree, this is a small change that can make it into v5 and I can help with rebasing.
The other day, two unrelated users had asked for it - here's one: https://stackoverflow.com/q/52152217/3160475
Comment From: prettybot
Please add this feature. It will be quite useful.
Comment From: krishnaff
The original feature request and PR were in 2013. Its 2019. Still waiting for this... :(
Comment From: kpfecteau
I know this is pretty old, but any chance this ever gets accepted into the current version?
Comment From: rookie7799
Nothing?
Comment From: HADB
Any updates?
Comment From: madolson
This seems pretty straight forward, I think someone just needs to go implement it.
Comment From: kshitijjolly-probo
+1
I think we can do a workaround for this using ZSCORE and ZCOUNT function as follows:
- Get the score for the sorted set entry using ZSCORE function - let suppose 12.5
- Get the count of entries having lesser score than the entry using ZCOUNT function - ZCOUNT myset -inf (12.5
Comment From: DuncanHouston
+1
I think we can do a workaround for this using ZSCORE and ZCOUNT function as follows:
- Get the score for the sorted set entry using ZSCORE function - let suppose 12.5
- 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)