Skip to content

Instantly share code, notes, and snippets.

@roidrage
Forked from qrush/gist:296921
Created May 26, 2010 17:41
Show Gist options
  • Save roidrage/414792 to your computer and use it in GitHub Desktop.
Save roidrage/414792 to your computer and use it in GitHub Desktop.
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