class RedisClient::Pooled

Constants

EMPTY_HASH

Public Class Methods

new( config, id: config.id, connect_timeout: config.connect_timeout, read_timeout: config.read_timeout, write_timeout: config.write_timeout, **kwargs ) click to toggle source
Calls superclass method RedisClient::Common::new
# File lib/redis_client/pooled.rb, line 11
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

Public Instance Methods

close() click to toggle source
# File lib/redis_client/pooled.rb, line 37
def close
  if @pool
    @mutex.synchronize do
      pool = @pool
      @pool = nil
      pool&.shutdown(&:close)
    end
  end
  nil
end
size() click to toggle source
# File lib/redis_client/pooled.rb, line 48
def size
  pool.size
end
then(options = EMPTY_HASH)
Alias for: with
with(options = EMPTY_HASH) { |client| ... } click to toggle source
# File lib/redis_client/pooled.rb, line 25
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
Also aliased as: then

Private Instance Methods

new_pool() click to toggle source
# File lib/redis_client/pooled.rb, line 82
def new_pool
  ConnectionPool.new(**@pool_kwargs) { @config.new_client }
end
pool() click to toggle source
# File lib/redis_client/pooled.rb, line 78
def pool
  @pool ||= @mutex.synchronize { new_pool }
end