I'm trying to implement a leaderboard with rankings, the data being stored as sorted sets in Redis. The part I'm trying to figure out is how to implement Dense (i.e. "1-2-2-3") ranking, where, for example, users are ranked thusly:
Score User Rank
---------------------
22 user1 1
21 user2 2
21 user3 2
21 user4 2
20 user5 3
20 user6 3
This answer: https://stackoverflow.com/a/14944280/2177 is almost what I need, but it amounts to "1-2-2-4" ranking, which is not desirable for my application, e.g.:
1-2-2-4 Ranking
Score User Rank
---------------------
22 user1 1
21 user2 2
21 user3 2
21 user4 2
20 user5 5
20 user6 5
This seems like it would be a fairly common use case. Has anyone successfully implemented such a thing in Redis, and if so, how?
What I ended up doing was adding a second sorted set that contains only the unique scores, which I can then query for their respective positions in the dense ranking.