Class: PulseMeter::Sensor::Counter

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

Direct Known Subclasses

HashedCounter, UniqCounter

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 Base

#annotate, #annotation, #initialize

Methods included from Mixins::Dumper

included

Constructor Details

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

Instance Method Details

#cleanupObject

Cleans up all sensor metadata in Redis



7
8
9
10
# File 'lib/pulse-meter/sensor/counter.rb', line 7

def cleanup
  redis.del(value_key)
  super
end

#event(value) ⇒ Object

Processes event by incremnting counter by given value

Parameters:

  • value (Fixnum)

    increment



19
20
21
# File 'lib/pulse-meter/sensor/counter.rb', line 19

def event(value)
  redis.incrby(value_key, value.to_i)
end

#incrObject

Increments counter value by 1



13
14
15
# File 'lib/pulse-meter/sensor/counter.rb', line 13

def incr
  event(1)
end

#valueFixnum

Gets counter value

Returns:

  • (Fixnum)


25
26
27
# File 'lib/pulse-meter/sensor/counter.rb', line 25

def value
  redis.get(value_key).to_i
end

#value_keyString

Gets redis key by which counter value is stored

Returns:

  • (String)


31
32
33
# File 'lib/pulse-meter/sensor/counter.rb', line 31

def value_key
  @value_key ||= "pulse_meter:value:#{name}"
end