created Redistat::Summary object

This commit is contained in:
2010-07-23 23:27:55 +03:00
parent 0f11eb66e1
commit 1c818024e5
3 changed files with 84 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ require "redistat/key"
require "redistat/label"
require "redistat/model"
require "redistat/scope"
require "redistat/summary"
module Redistat

29
lib/redistat/summary.rb Normal file
View File

@@ -0,0 +1,29 @@
module Redistat
class Summary
include Database
extend Database
def self.update_all(key, stats = {}, depth_limit = nil)
stats ||= {}
depth_limit ||= key.depth
return false if stats.size == 0
depths.each do |depth|
update(key, stats, depth)
break if depth == depth_limit
end
end
private
def self.update(key, stats, depth)
stats.each do |field, value|
db.hincrby key.to_s(depth), field, value
end
end
def self.depths
[:year, :month, :day, :hour, :min, :sec, :usec]
end
end
end