lib/tabs/metrics/counter.rb in tabs-0.9.1 vs lib/tabs/metrics/counter.rb in tabs-1.0.0

- old
+ new

@@ -19,12 +19,12 @@ true end def stats(period, resolution) timestamps = timestamp_range period, resolution - keys = timestamps.map do |ts| - "stat:counter:#{key}:count:#{Tabs::Resolution.serialize(resolution, ts)}" + keys = timestamps.map do |timestamp| + storage_key(resolution, timestamp) end values = mget(*keys).map do |v| { "timestamp" => timestamps.shift, @@ -41,15 +41,24 @@ def drop! del_by_prefix("stat:counter:#{key}") end + def drop_by_resolution!(resolution) + del_by_prefix("stat:counter:#{key}:count:#{resolution}") + end + + def storage_key(resolution, timestamp) + formatted_time = Tabs::Resolution.serialize(resolution, timestamp) + "stat:counter:#{key}:count:#{resolution}:#{formatted_time}" + end + private def increment_resolution(resolution, timestamp) - formatted_time = Tabs::Resolution.serialize(resolution, timestamp) - stat_key = "stat:counter:#{key}:count:#{formatted_time}" - incr(stat_key) + store_key = storage_key(resolution, timestamp) + incr(store_key) + Tabs::Resolution.expire(resolution, store_key, timestamp) end def increment_total incr("stat:counter:#{key}:total") end