mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
created Redistat::Summary object
This commit is contained in:
@@ -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
29
lib/redistat/summary.rb
Normal 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
|
||||
Reference in New Issue
Block a user