Method: Oxblood::Pool#with

Defined in:
lib/oxblood/pool.rb

#with {|session| ... } ⇒ Object

Run commands on a connection from pool. Connection is wrapped to the Session.

Examples:

pool = Oxblood::Pool.new(size: 8)
pool.with do |session|
  session.set('hello', 'world')
  session.get('hello')
end # => 'world'

Yields:

  • (session)

    provide Session to a block

Yield Returns:

  • response from the last executed operation



40
41
42
43
44
45
46
47
48
49
# File 'lib/oxblood/pool.rb', line 40

def with
  conn = @pool.checkout
  session = Session.new(conn)
  yield(session)
ensure
  if conn
    session.discard if conn.in_transaction?
    @pool.checkin
  end
end