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, #fetch_values, #initialize, #key?, #load, new, #slice, #values_at

Methods included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

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

Instance Method Details

#each_keyObject

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.



368
369
370
371
372
373
374
375
# File 'lib/moneta/adapters/sequel.rb', line 368

def each_key
  return super unless block_given? && @each_key_server && @table.respond_to?(:stream)
  # Order is not required when streaming
  @table.server(@each_key_server).select(key_column).paged_each do |row|
    yield row[key_column]
  end
  self
end

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



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/moneta/adapters/sequel.rb', line 339

def increment(key, amount = 1, options = {})
  @backend.transaction do
    # this creates a row-level lock even if there is no existing row (a
    # "gap lock").
    if row = @load_for_update.call(key: key)
      # Integer() will raise an exception if the existing value cannot be parsed
      amount += Integer(row[value_column])
      @increment_update.call(key: key, value: amount)
    else
      @create.call(key: key, value: amount)
    end
    amount
  end
rescue ::Sequel::SerializationFailure # Thrown on deadlock
  tries ||= 0
  (tries += 1) <= 3 ? retry : raise
end

#merge!(pairs, options = {}, &block) ⇒ 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.



357
358
359
360
361
362
363
364
365
366
# File 'lib/moneta/adapters/sequel.rb', line 357

def merge!(pairs, options = {}, &block)
  @backend.transaction do
    pairs = yield_merge_pairs(pairs, &block) if block_given?
    @table.
      on_duplicate_key_update.
      import([key_column, value_column], blob_pairs(pairs).to_a)
  end

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



334
335
336
337
# File 'lib/moneta/adapters/sequel.rb', line 334

def store(key, value, options = {})
  @store.call(key: key, value: blob(value))
  value
end