class RedisClient
def ensure_connected(retryable: true)
def ensure_connected(retryable: true) close if !config.inherit_socket && @pid != PIDCache.pid if @disable_reconnection if block_given? yield @raw_connection else @raw_connection end elsif retryable tries = 0 connection = nil begin connection = raw_connection if block_given? yield connection else connection end rescue ConnectionError, ProtocolError => error close if !@disable_reconnection && config.retry_connecting?(tries, error) tries += 1 retry else raise end end else previous_disable_reconnection = @disable_reconnection connection = ensure_connected begin @disable_reconnection = true yield connection rescue ConnectionError, ProtocolError close raise ensure @disable_reconnection = previous_disable_reconnection end end end