Module: Moneta::Adapters::Sequel::MySQL Private

Defined in:
lib/moneta/adapters/sequel/mysql.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.

Instance Method Summary collapse

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.


40
41
42
43
44
45
46
47
# File 'lib/moneta/adapters/sequel/mysql.rb', line 40

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.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moneta/adapters/sequel/mysql.rb', line 11

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.


29
30
31
32
33
34
35
36
37
38
# File 'lib/moneta/adapters/sequel/mysql.rb', line 29

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.


6
7
8
9
# File 'lib/moneta/adapters/sequel/mysql.rb', line 6

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