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