Class: Moneta::Adapters::Sequel::MySQL Private

Inherits:
Moneta::Adapters::Sequel show all
Defined in:
lib/moneta/adapters/sequel.rb

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

Constant Summary

Constants inherited from Moneta::Adapters::Sequel

UniqueConstraintViolation

Instance Attribute Summary

Attributes inherited from Moneta::Adapters::Sequel

#backend, #key_column, #value_column

Instance Method Summary collapse

Methods inherited from Moneta::Adapters::Sequel

#clear, #close, #create, #delete, #initialize, #key?, #load, new

Methods included from Defaults

#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #key?, #merge!, #slice, #supports?, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

This class inherits a constructor from Moneta::Adapters::Sequel

Instance Method Details

#increment(key, amount = 1, options = {}) ⇒ 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.


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/moneta/adapters/sequel.rb', line 191

def increment(key, amount = 1, options = {})
  @backend.transaction do
    if existing = load(key)
      Integer(existing)
    end
    @table.
      on_duplicate_key_update(
        value_column => ::Sequel.+(value_column, ::Sequel[:values].function(value_column))).
      insert(key_column => key, value_column => amount)
    load(key).to_i
  end
rescue ::Sequel::SerializationFailure # Thrown on deadlock
  tries ||= 0
  (tries += 1) <= 3 ? retry : raise
end

#store(key, value, options = {}) ⇒ 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.


184
185
186
187
188
189
# File 'lib/moneta/adapters/sequel.rb', line 184

def store(key, value, options = {})
  @table.
    on_duplicate_key_update(value_column => ::Sequel[:values].function(value_column)).
    insert(key_column => key, value_column => blob(value))
  value
end