Sha256: 45fd6a8aae15bce7e03fcec801daa953c996a1877e8afbb14295fd3d4a28d7f6

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# typed: true
require 'ddtrace/contrib/redis/vendor/resolver'

module Datadog
  module Contrib
    module Redis
      module Configuration
        UNIX_SCHEME = 'unix'.freeze

        # Converts String URLs and Hashes to a normalized connection settings Hash.
        class Resolver < Contrib::Configuration::Resolver
          # @param [Hash,String] Redis connection information
          def resolve(hash)
            super(parse_matcher(hash))
          end

          protected

          def parse_matcher(matcher)
            matcher = { url: matcher } if matcher.is_a?(String)

            normalize(connection_resolver.resolve(matcher))
          end

          def normalize(hash)
            return { url: hash[:url] } if hash[:scheme] == UNIX_SCHEME

            # Connexion strings are always converted to host, port, db and scheme
            # but the host, port, db and scheme will generate the :url only after
            # establishing a first connexion
            {
              host: hash[:host],
              port: hash[:port],
              db: hash[:db],
              scheme: hash[:scheme]
            }
          end

          def connection_resolver
            @connection_resolver ||= ::Datadog::Contrib::Redis::Vendor::Resolver.new
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/contrib/redis/configuration/resolver.rb
ddtrace-0.54.1 lib/ddtrace/contrib/redis/configuration/resolver.rb
ddtrace-0.54.0 lib/ddtrace/contrib/redis/configuration/resolver.rb
ddtrace-0.53.0 lib/ddtrace/contrib/redis/configuration/resolver.rb
ddtrace-0.52.0 lib/ddtrace/contrib/redis/configuration/resolver.rb