Method: Moneta::Adapters::LMDB#increment
- Defined in:
- lib/moneta/adapters/lmdb.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.
65 66 67 68 69 70 71 72 |
# File 'lib/moneta/adapters/lmdb.rb', line 65 def increment(key, amount = 1, = {}) @backend.transaction do value = @db.get(key) value = Utils.to_int(value) + amount @db.put(key, value.to_s, Utils.only(, *PUT_FLAGS)) value end end |