Method: Redis::Counter#increment

Defined in:
lib/redis/counter.rb

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

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.



44
45
46
47
# File 'lib/redis/counter.rb', line 44

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