You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Reacted by Chris Barnes, Kyle Petrovich, Vignesh Gurusamy, Emil Kantis, medmolryan, Kit Sunde, aloha and Anton Van Eechaute
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):
the user's rank (zRevRank)
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)
Activity
antirez commentedon Jul 17, 2013
I'm sorry to move that to 3.0, not enough time for a serious review for 2.8.
venky1 commentedon Sep 18, 2014
Is this available as part of 3.0 beta.
mattsta commentedon Sep 18, 2014
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
Add ZRANK UNIQUE
Add ZRANK UNIQUE
adamscherer commentedon Jun 22, 2015
Any guidance on whether this will make the 3.2 release?
doncorsean-private commentedon Jul 22, 2015
I could use this as well (fingers crossed).
a-chernykh commentedon Aug 24, 2015
I am looking forward for this to be merged. We need leaderboards with ties in our app.
doncorsean-private commentedon Aug 27, 2015
I just built it from source ;) AWS doesn't deploy a recent version in elasticache anyhow
swinbank commentedon Mar 5, 2016
Looking forward to this. Should
ZCOUNTreceive this treatment, too?AlainPilon commentedon Aug 8, 2016
+1 on this.
henryren commentedon Oct 30, 2016
+1 on this.
5 remaining items
prettybot commentedon Nov 8, 2018
Please add this feature. It will be quite useful.
krishnaff commentedon Feb 18, 2019
The original feature request and PR were in 2013.
Its 2019. Still waiting for this... :(
kpfecteau commentedon May 10, 2020
I know this is pretty old, but any chance this ever gets accepted into the current version?
rookie7799 commentedon Aug 10, 2020
Nothing?
HADB commentedon Sep 16, 2021
Any updates?
madolson commentedon Sep 16, 2021
This seems pretty straight forward, I think someone just needs to go implement it.
kshitijjolly-probo commentedon Sep 24, 2021
+1
I think we can do a workaround for this using ZSCORE and ZCOUNT function as follows:
DuncanHouston commentedon Jun 9, 2022
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):
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)
Squashed 'deps/hiredis/' changes from f8de9a4bd..b6a052fe0
Improve code readability in dict.c (redis#943)