class HAJ::Pool::Generic

Class to provide a POC for better pooling.

Constants

DEFAULT_DATABASE
DEFAULT_HOST
DEFAULT_PORT
DEFAULT_TIMEOUT

Public Class Methods

new(opts = {}) click to toggle source
# File lib/haj/pool/generic.rb, line 12
def initialize(opts = {})
  config = HAJ::Pool::Config.new(opts)

  host     = opts.fetch(:host) { DEFAULT_HOST }
  port     = opts.fetch(:port) { DEFAULT_PORT }
  timeout  = opts.fetch(:timeout) { DEFAULT_TIMEOUT }
  password = opts.fetch(:password) { nil }
  database = opts.fetch(:database) { DEFAULT_DATABASE }
  name     = opts.fetch(:name) { nil }

  @inner_pool = HAJ::Jedis::Pool.new(
    config,
    host,
    port,
    timeout,
    password,
    database,
    name
  )
end

Public Instance Methods

hold() { |connection| ... } click to toggle source
# File lib/haj/pool/generic.rb, line 33
def hold
  connection = @inner_pool.resource

  yield connection
ensure
  connection.close if connection
end