class RedisClient::Pooled

def close

def close
  if @pool
    @mutex.synchronize do
      pool = @pool
      @pool = nil
      pool&.shutdown(&:close)
    end
  end
  nil
end

def initialize(

def initialize(
  config,
  id: config.id,
  connect_timeout: config.connect_timeout,
  read_timeout: config.read_timeout,
  write_timeout: config.write_timeout,
  **kwargs
)
  super(config, id: id, connect_timeout: connect_timeout, read_timeout: read_timeout, write_timeout: write_timeout)
  @pool_kwargs = kwargs
  @pool = new_pool
  @mutex = Mutex.new
end

def new_pool

def new_pool
  ConnectionPool.new(**@pool_kwargs) { @config.new_client }
end

def pool

def pool
  @pool ||= @mutex.synchronize { new_pool }
end

def size

def size
  pool.size
end

def with(options = EMPTY_HASH)

def with(options = EMPTY_HASH)
  pool.with(options) do |client|
    client.connect_timeout = connect_timeout
    client.read_timeout = read_timeout
    client.write_timeout = write_timeout
    yield client
  end
rescue ConnectionPool::TimeoutError => error
  raise CheckoutTimeoutError, "Couldn't checkout a connection in time: #{error.message}"
end