Sha256: 60f0dc412df8d19d365a332cc7a5e433dc26fe141c9354182d416ef6bcad9fdb

Contents?: true

Size: 1.19 KB

Versions: 93

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.incrby("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.decrby("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

93 entries across 93 versions & 7 rubygems

Version Path
resque-1.18.4 lib/resque/stat.rb
resque-1.18.3 lib/resque/stat.rb
resque-1.18.2 lib/resque/stat.rb
resque-1.18.1 lib/resque/stat.rb
resque-1.18.0 lib/resque/stat.rb
resque-1.17.1 lib/resque/stat.rb
resque-1.17.0 lib/resque/stat.rb
resque-1.16.1 lib/resque/stat.rb
resque-1.16.0 lib/resque/stat.rb
resque-1.15.0 lib/resque/stat.rb
resque-1.14.0 lib/resque/stat.rb
resque-1.13.0 lib/resque/stat.rb
resque-1.11.0 lib/resque/stat.rb
resque-1.12.0 lib/resque/stat.rb
resque-1.10.0 lib/resque/stat.rb
resque-1.9.10 lib/resque/stat.rb
resque-1.9.9 lib/resque/stat.rb
resque-1.9.8 lib/resque/stat.rb
resque-1.9.7 lib/resque/stat.rb
resque-1.9.5 lib/resque/stat.rb