Redis sorted set leader board ranking on same score

If your leaderboard's scores are "small" enough, you may get away with using a combination of the score and the timestamp (e.g. 123.111455234, where 123 is the score). However, since the Sorted Set score is a double floating point, you may lose precision.

Alternatively, keep two Sorted Sets - one with each player's leaderboard score and the other with each player's score timestamp, and use both to determine the order.

Or, use a single sorted set for the leader board, encode the timestamp as part of the member and rely on lexicographical ordering.


I found one solution to this problem. In my case, the score is an integer so I converted it into decimal and added Long.MAX_VALUE - System.nanoTime() after decimal. So the final score code will be like

double finalScore = score.(Long.MAX_VALUE - System.nanoTime());

So the final score of the player who scored first would be higher than the second one. Please let me know if you have any better solution.