Method: Redis::Counter#increment

Defined in:
lib/redis/counter.rb

#increment(by = 1, &block) ⇒ Object Also known as: incr, incrby

Increment the counter atomically and return the new value. If passed a block, that block will be evaluated with the new value of the counter as an argument. If the block returns nil or throws an exception, the counter will automatically be decremented to its previous value. This method is aliased as incr() for brevity.



68
69
70
71
72
73
# File 'lib/redis/counter.rb', line 68

def increment(by=1, &block)
  allow_expiration do
    val = redis.incrby(key, by).to_i
    block_given? ? rewindable_block(:decrement, by, val, &block) : val
  end
end