Sha256: 3b43cba14c181193fc39285a4eb0aaabc7912bf0a81d1f9de98eaff4b9176f8f

Contents?: true

Size: 774 Bytes

Versions: 22

Compression:

Stored size: 774 Bytes

Contents

require 'json'

# Static hashed counter to count values by multiple keys
module PulseMeter
  module Sensor
    class HashedCounter < Counter

      # Increments counter value by 1 for given key
      # @param key [String] key to be incremented
      def incr(key)
        event({key => 1})
      end

      # Processes events for multiple keys
      # @param data [Hash] hash where keys represent counter keys
      #   and values are increments for their keys
      def event(data)
        data.each_pair {|k, v| redis.hincrby(value_key, k, v.to_i)}
      end

      # Returs data stored in counter
      # @return [Hash]
      def value
        redis.
          hgetall(value_key).
          inject(Hash.new(0)) {|h, (k, v)| h[k] = v.to_i; h}
      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/hashed_counter.rb
pulse-meter-0.2.2 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.2.1 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.2.0 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-client-backport-0.1.4 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.11 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-client-backport-0.1.3 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.10 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-client-backport-0.1.2 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.9 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-client-backport-0.1.1 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.8 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.7 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.6 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.5 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.4 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.3 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.2 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-0.1.1 lib/pulse-meter/sensor/hashed_counter.rb
pulse-meter-client-backport-0.1.0 lib/pulse-meter/sensor/hashed_counter.rb