Sha256: aaed52963bcb0b03e5fb74f82a8697fbdf7413232200c0043df3eb9fef20840c

Contents?: true

Size: 756 Bytes

Versions: 22

Compression:

Stored size: 756 Bytes

Contents

# Static counter
module PulseMeter
  module Sensor
    class Counter < Base

      # Cleans up all sensor metadata in Redis
      def cleanup
        redis.del(value_key)
        super
      end

      # Increments counter value by 1
      def incr
        event(1)
      end

      # Processes event by incremnting counter by given value
      # @param value [Fixnum] increment
      def event(value)
        redis.incrby(value_key, value.to_i)
      end

      # Gets counter value
      # @return [Fixnum]
      def value
        redis.get(value_key).to_i
      end
      
      # Gets redis key by which counter value is stored
      # @return [String]
      def value_key
        @value_key ||= "pulse_meter:value:#{name}"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
pulse-meter-0.2.3 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.2.2 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.2.1 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.2.0 lib/pulse-meter/sensor/counter.rb
pulse-meter-client-backport-0.1.4 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.11 lib/pulse-meter/sensor/counter.rb
pulse-meter-client-backport-0.1.3 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.10 lib/pulse-meter/sensor/counter.rb
pulse-meter-client-backport-0.1.2 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.9 lib/pulse-meter/sensor/counter.rb
pulse-meter-client-backport-0.1.1 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.8 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.7 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.6 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.5 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.4 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.3 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.2 lib/pulse-meter/sensor/counter.rb
pulse-meter-0.1.1 lib/pulse-meter/sensor/counter.rb
pulse-meter-client-backport-0.1.0 lib/pulse-meter/sensor/counter.rb