Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
gemcutter => redis downloads spec
=================================
keys
----
downloads => global counter for all gem downloads
downloads:today => sorted set for downloads from today
downloads:rubygem:rails => counter for all rails downloads
downloads:version:rails-2.3.5 => counter for all rails 2.3.5 downloads
downloads:rubygem_daily:rails => daily download hash for this rubygem
downloads:version_daily:rails-2.3.5 => daily download hash for this version
Daily download hash format:
{
'2010-02-01' : 134,
'2010-02-02' : 289,
...
}
on a download
-------------
Let's say /gems/bundler-0.9.2.gem was hit...
INCR downloads
INCR downloads:rubygem:bundler
INCR downloads:version:bundler-0.9.2
ZINCRBY downloads:today 1 bundler-0.9.2
on a daily cron
---------------
RENAME downloads:today downloads:yesterday
keys = ZRANGE downloads:yesterday 0 -1
keys.each do |key|
version = Version.find_by_full_name(key)
downloads = ZSCORE downloads:yesterday key
HINCRBY downloads:version_daily:#{version.full_name} Date.today downloads
HINCRBY downloads:rubygem_daily:#{version.rubygem.name} Date.today downloads
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment