Method: Moneta::IncrementSupport#increment
- Defined in:
- lib/moneta/increment_support.rb
#increment(key, amount = 1, options = {}) ⇒ Object
Note:
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically increment integer value with key
This method also accepts negative amounts.
5 6 7 8 9 10 |
# File 'lib/moneta/increment_support.rb', line 5 def increment(key, amount = 1, = {}) existing = load(key, ) value = (existing == nil ? 0 : Integer(existing)) + amount store(key, value.to_s, ) value end |