Class: PulseMeter::Sensor::HashedCounter
- 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
Instance Method Summary collapse
-
#event(data) ⇒ Object
Processes events for multiple keys.
-
#incr(key) ⇒ Object
Increments counter value by 1 for given key.
-
#value ⇒ Hash
Returs data stored in counter.
Methods inherited from Counter
Methods inherited from Base
#annotate, #annotation, #cleanup, #initialize
Methods included from Mixins::Dumper
Constructor Details
This class inherits a constructor from PulseMeter::Sensor::Base
Instance Method Details
#event(data) ⇒ Object
Processes events for multiple keys
17 18 19 |
# File 'lib/pulse-meter/sensor/hashed_counter.rb', line 17 def event(data) data.each_pair {|k, v| redis.hincrby(value_key, k, v.to_i)} end |
#incr(key) ⇒ Object
Increments counter value by 1 for given key
10 11 12 |
# File 'lib/pulse-meter/sensor/hashed_counter.rb', line 10 def incr(key) event({key => 1}) end |
#value ⇒ Hash
Returs data stored in counter
23 24 25 26 27 |
# File 'lib/pulse-meter/sensor/hashed_counter.rb', line 23 def value redis. hgetall(value_key). inject(Hash.new(0)) {|h, (k, v)| h[k] = v.to_i; h} end |