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.7.1 lib/resque/stat.rb
resque-1.7.0 lib/resque/stat.rb
resque-1.6.1 lib/resque/stat.rb
resque-1.6.0 lib/resque/stat.rb
resque-1.5.2 lib/resque/stat.rb
resque-1.5.1 lib/resque/stat.rb
scotttam-resque-0.0.5 lib/resque/stat.rb
scotttam-resque-0.0.4 lib/resque/stat.rb
scotttam-resque-0.0.3 lib/resque/stat.rb
scotttam-resque-0.0.2 lib/resque/stat.rb
scotttam-resque-0.0.1 lib/resque/stat.rb
grockit-resque-1.5.0 lib/resque/stat.rb
resque-1.5.0 lib/resque/stat.rb
resque-1.4.0 lib/resque/stat.rb
resque-1.3.1 lib/resque/stat.rb
resque-1.3.0 lib/resque/stat.rb
resque-1.2.3 lib/resque/stat.rb
resque-1.2.1 lib/resque/stat.rb
resque-1.2.0 lib/resque/stat.rb
jerefrer-resque-1.1.0 lib/resque/stat.rb