Sha256: 7c0389db75d0b9aee791a8bfbcadc5f7d3d3c7681c7e3e78e3b5fea25106bf53

Contents?: true

Size: 1.19 KB

Versions: 23

Compression:

Stored size: 1.19 KB

Contents

module Resque
  # The stat subsystem. Used to keep track of integer counts.
  #
  #   Get a stat:  Stat[name]
  #   Incr a stat: Stat.incr(name)
  #   Decr a stat: Stat.decr(name)
  #   Kill a stat: Stat.clear(name)
  module Stat
    extend self
    extend Helpers

    # Returns the int value of a stat, given a string stat name.
    def get(stat)
      redis.get("stat:#{stat}").to_i
    end

    # Alias of `get`
    def [](stat)
      get(stat)
    end

    # For a string stat name, increments the stat by one.
    #
    # Can optionally accept a second int parameter. The stat is then
    # incremented by that amount.
    def incr(stat, by = 1)
      redis.incr("stat:#{stat}", by)
    end

    # Increments a stat by one.
    def <<(stat)
      incr stat
    end

    # For a string stat name, decrements the stat by one.
    #
    # Can optionally accept a second int parameter. The stat is then
    # decremented by that amount.
    def decr(stat, by = 1)
      redis.decr("stat:#{stat}", by)
    end

    # Decrements a stat by one.
    def >>(stat)
      decr stat
    end

    # Removes a stat from Redis, effectively setting it to 0.
    def clear(stat)
      redis.del("stat:#{stat}")
    end
  end
end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
resque-1.1.0 lib/resque/stat.rb
resque-1.0.0 lib/resque/stat.rb
resque-0.2.0 lib/resque/stat.rb