I suggest you keep a set with a rating for all participants:
leaderboard = { id1: score1, id2: score2, ... }
And a set for each type (gender, country, etc.):
members.male = { id1, id2, ... } members.au = { id2, id3, ... }
Then you do ZINTERSTORE
:
zinterstore leaderboard.male 2 leaderboard members.male
Or, to get the leaderboard for male members:
zinterstore leaderboard.au.male 3 leaderboard members.male members.au
You can control how the count of results for a sorted set should be calculated using WEIGHTS
and AGGREGATE
.
If you do not want to save result sets for a long time, you could EXPIRE
them and only build a new set if it does not exist.
source share