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, #initialize

Methods included from Mixins::Dumper

included

Constructor Details

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

Instance Method Details

#event(data) ⇒ Object

Processes events for multiple keys

Parameters:

  • data (Hash)

    hash where keys represent counter keys and values are increments for their 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

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)


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