Module: Moneta::IncrementSupport Private

Included in:
Adapters::LRUHash, Adapters::Memory, Adapters::Sqlite, WeakIncrement
Defined in:
lib/moneta/mixins.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


292
293
294
# File 'lib/moneta/mixins.rb', line 292

def self.included(base)
  base.supports(:increment) if base.respond_to?(:supports)
end

Instance Method Details

#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.

Parameters:

  • key (Object)
  • amount (Integer) (defaults to: 1)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value from store


286
287
288
289
290
# File 'lib/moneta/mixins.rb', line 286

def increment(key, amount = 1, options = {})
  value = Utils.to_int(load(key, options)) + amount
  store(key, value.to_s, options)
  value
end