Sha256: 18c5488f7edad407526ab0006f610053ff2ce5196d47b1863c1f0644d3feafbc
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
require 'connection_pool' require 'oxblood/session' require 'oxblood/pipeline' require 'oxblood/connection' module Oxblood # Create connection pool. For the most use cases this is entrypoint API. # # @example # pool = Oxblood::Pool.new(size: 8) # pool.with { |c| c.ping } # => 'PONG' class Pool # Initialize connection pool # # @param [Hash] options Connection options # # @option options [Float] :timeout (1.0) Connection acquisition timeout. # @option options [Integer] :size Pool size. # @option options [Hash] :connection see {Connection#initialize} def initialize(options = {}) timeout = options.fetch(:timeout, 1.0) size = options.fetch(:size) @pool = ConnectionPool.new(size: size, timeout: timeout) do Connection.new(options.fetch(:connection, {})) end end # Run commands on a connection from pool. # Connection is wrapped to the {Session}. # @yield [session] provide {Session} to a block # @yieldreturn response from the last executed operation # # @example # pool = Oxblood::Pool.new(size: 8) # pool.with do |session| # session.set('hello', 'world') # session.get('hello') # end # => 'world' def with conn = @pool.checkout session = Session.new(conn) yield(session) ensure session.discard if conn.in_transaction? @pool.checkin if conn end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oxblood-0.1.0.dev12 | lib/oxblood/pool.rb |
oxblood-0.1.0.dev11 | lib/oxblood/pool.rb |