agoragames / leaderboard

Leaderboards backed by Redis in Ruby
https://rubygems.org/gems/leaderboard
MIT License
478 stars 65 forks source link

Question: what is the best approach for handle a weekly leader board? #52

Closed robertomiranda closed 9 years ago

robertomiranda commented 9 years ago

just came to my mind something like create a leader board per week?

  highscore_lb = Leaderboard.new("highscores_weekly_#{Time.now.strftime("%V-%Y")}")

cc:// @czarneckid

robertomiranda commented 9 years ago

another thing is what about the historically data? is there's a way to expire them from memory and save it on disk? I couldn't imagine a full year weekly ranking loaded in memory

czarneckid commented 9 years ago

The naming approach seems fine.

If you want to preserve the leaderboard data, but not have it take up memory, you'd have to save the dataset to disk by issuing one of the commands to persist to disk such as BGSAVE. At that point, you'd want to preserve the Redis database (probably .rdb) by copying it from the Redis DB save location and then you could clean up or remove the historical data from the CLI. The drawback is that you lose the ability to pull up that historical data.

It's also relatively straightforward to assess how much memory would be taken up with a leaderboard(s). See https://github.com/agoragames/leaderboard/#performance-metrics for some approaches. You might want to look at bulk insert.

robertomiranda commented 9 years ago

@czarneckid thanks, about the historical data how about after call BGSAVE save it in a relational database like Postgres using the JSON or HSTORE?. And if necessary to make some operations can load it back in Redis again, though that would be an unusual case

czarneckid commented 9 years ago

On further thought, this could get complex, but might be achievable with some combination of DUMP and RESTORE and storing that data in another data store. There is also the MIGRATE command that could be used if you started another redis instance with the old data and migrated data.