module Tarantool
Constants
- CODE_TO_EXCEPTION
- DEFAULT_PORT
autoload :Record, 'tarantool/record' autoload :LightRecord, 'tarantool/light_record'
- RECORD_VERSION
- VERSION
Public Class Methods
new(conf)
click to toggle source
# File lib/tarantool.rb, line 17 def new(conf) if conf[:host] shards = [ [ _fix_connection(conf) ] ] else shards = conf[:servers] unless shards.is_a? Array shards = [ shards ] end unless shards.first.is_a? Array shards = [ shards ] end shards = shards.map{|shard| shard.map{|server| _fix_connection(server)}} end replica_strategy = conf[:replica_strategy] || :round_robin if %w{round_robin master_first}.include?(replica_strategy) replica_strategy = replica_strategy.to_sym end unless [:round_robin, :master_first, :prefer_slave].include?(replica_strategy) raise ArgumentError, "Shard strategy could be :round_robin or :master_first, got #{replica_strategy.inspect}" end previous_shards_count = conf[:previous_shards_count] insert_to_previous_shard = conf[:insert_to_previous_shard] case conf[:type] || :block when :em, :em_fiber require 'tarantool/fiber_db' FiberDB.new(shards, replica_strategy, previous_shards_count, insert_to_previous_shard) when :em_cb, :em_callback require 'tarantool/callback_db' CallbackDB.new(shards, replica_strategy, previous_shards_count, insert_to_previous_shard) when :block require 'tarantool/block_db' BlockDB.new(shards, replica_strategy, previous_shards_count, insert_to_previous_shard) else raise "Unknown Tarantool connection type #{conf[:type]}" end end
Private Class Methods
_fix_connection(conn)
click to toggle source
# File lib/tarantool.rb, line 58 def _fix_connection(conn) if conn.is_a? Hash conn = [conn[:host], conn[:port]].compact.join(':') end if conn.is_a? String host, port = conn.split(':') port ||= DEFAULT_PORT conn = [host, port.to_i] end raise ArgumentError, "Wrong connection declaration #{conn}" unless conn.is_a? Array conn end