Skip to content

Instantly share code, notes, and snippets.

@courtenay
Created August 1, 2011 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save courtenay/1118530 to your computer and use it in GitHub Desktop.
Save courtenay/1118530 to your computer and use it in GitHub Desktop.
# sample stats recording code
base = "w:#{site_id}:#{word}"
# hits per year
REDIS.incr "#{base}:#{created_at.year}"
# hits per month
REDIS.incr "#{base}:#{created_at.month}-#{created_at.year}"
# hits per day
REDIS.incr "#{base}:#{created_at.day}-#{created_at.month}-#{created_at.year}"
# hits by hour-of-day this month
REDIS.incr "#{base}:#{created_at.hour}h#{created_at.month}-#{created_at.year}"
So then to get the list of words for this month there's very little aggregation:
REDIS.sort wordlist, { :by => "w:#{site_id}:*:#{end_date.month}-#{end_date.year}", :order => "DESC" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment