lib/rhoconnect/stats/record.rb in rhoconnect-3.4.5 vs lib/rhoconnect/stats/record.rb in rhoconnect-4.0.0.beta.10

- old
+ new

@@ -8,23 +8,23 @@ # Also supports updating the value with a block (useful for averages) def set(metric, value = 0) start = (Time.now.to_i / resolution(metric)) * resolution(metric) current, current_score = 0, start Store.lock(key(metric)) do - range = Store.db.zrevrange(key(metric), 0, 0) + range = Store.zrevrange(key(metric), 0, 0) if !range.empty? member = range[0] m_current = member.split(':')[0] - m_current_score = Store.db.zscore(key(metric), member).to_i + m_current_score = Store.zscore(key(metric), member).to_i if m_current_score > (start - resolution(metric)) - Store.db.zrem(key(metric), member) + Store.zrem(key(metric), member) current, current_score = m_current, m_current_score end end value = block_given? ? yield(current, value) : value - Store.db.zadd(key(metric), current_score, "#{value}:#{start}") - Store.db.zremrangebyscore(key(metric), 0, start - record_size(metric)) + Store.zadd(key(metric), current_score, "#{value}:#{start}") + Store.zremrangebyscore(key(metric), 0, start - record_size(metric)) end end def add(metric, value = 1) set(metric,value) { |current,value| current.to_i + value } @@ -54,19 +54,19 @@ yield end end def keys(glob='*') - Store.db.keys(key(glob)).collect {|c| c[5..-1]} + Store.keys(key(glob)).collect {|c| c[5..-1]} end def reset(metric) - Store.db.del(key(metric)) + Store.flush_data(key(metric)) end def reset_all - Store.flash_data('stat:*') + Store.flush_data('stat:*') end # Returns simple string metric def get_value(metric) Store.get_value(key(metric)) @@ -77,11 +77,11 @@ Store.set_value(key(metric), value) end # Returns the metric data, uses array indexing def range(metric, start, finish = -1) - Store.db.zrange(key(metric), start, finish) + Store.zrange(key(metric), start, finish) end # Returns the resolution for a given metric, default 60 seconds def resolution(metric) resolution = STATS_RECORD_RESOLUTION rescue nil @@ -94,10 +94,10 @@ size || 60 * 24 * 31 #=> 44640 minutes end # Returns redis object type for a record def rtype(metric) - Store.db.type(key(metric)) + Store.doc_type(key(metric)) end def key(metric) "stat:#{metric}" end \ No newline at end of file