Sha256: e2d76352b2139fb6acdbdb163d086838c0ff5e576b54c6de72692e36be9537b1

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 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

    def redis
      warn '[Resque] [Deprecation] Resque::Stat #redis method is deprecated (please use #data_strore)'
      data_store
    end

    def data_store
      @data_store ||= Resque.redis
    end

    def data_store=(data_store)
      @data_store = data_store
    end

    # Returns the int value of a stat, given a string stat name.
    def get(stat)
      data_store.stat(stat)
    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, **opts)
      data_store.increment_stat(stat, by, **opts)
    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)
      data_store.decrement_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, **opts)
      data_store.clear_stat(stat, **opts)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
resque-2.6.0 lib/resque/stat.rb
resque-2.5.0 lib/resque/stat.rb
resque-2.4.0 lib/resque/stat.rb
resque-2.3.0 lib/resque/stat.rb