Class: PulseMeter::Sensor::HashedCounter

Inherits:
Counter
  • Object
show all
Defined in:
lib/pulse-meter/sensor/hashed_counter.rb

Constant Summary

Constants included from Mixins::Dumper

Mixins::Dumper::DUMP_REDIS_KEY

Instance Attribute Summary

Attributes inherited from Base

#name, #redis

Instance Method Summary collapse

Methods inherited from Counter

#cleanup, #value_key

Methods inherited from Base

#annotate, #annotation, #cleanup, #event, #initialize

Methods included from Mixins::Dumper

included

Constructor Details

This class inherits a constructor from PulseMeter::Sensor::Base

Instance Method Details

#incr(key) ⇒ Object

Increments counter value by 1 for given key

Parameters:

  • key (String)

    key to be incremented



10
11
12
# File 'lib/pulse-meter/sensor/hashed_counter.rb', line 10

def incr(key)
  event({key => 1})
end

#valueHash

Returs data stored in counter

Returns:

  • (Hash)


16
17
18
19
20
# File 'lib/pulse-meter/sensor/hashed_counter.rb', line 16

def value
  redis.
    hgetall(value_key).
    inject(Hash.new(0)) {|h, (k, v)| h[k] = v.to_i; h}
end