Class: Dalli::Elasticache::AutoDiscovery::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/elasticache/auto_discovery/endpoint.rb

Overview

This is a representation of the configuration endpoint for a memcached cluster. It encapsulates information returned from that endpoint.

Constant Summary collapse

ENDPOINT_REGEX =

Matches DNS/IPv4 like “my-host.cache.aws.com:11211” or bracketed IPv6 like “[::1]:11211”

/^([-_.a-zA-Z0-9]+|\[[a-fA-F0-9:]+\])(?::(\d+))?$/
DEFAULT_PORT =
11_211

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr, timeout: nil, ssl_context: nil) ⇒ Endpoint

Returns a new instance of Endpoint.



18
19
20
21
22
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 18

def initialize(addr, timeout: nil, ssl_context: nil)
  @host, @port = parse_endpoint_address(addr)
  @timeout = timeout
  @ssl_context = ssl_context
end

Instance Attribute Details

#hostObject (readonly)

Endpoint configuration



13
14
15
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 13

def host
  @host
end

#portObject (readonly)

Endpoint configuration



13
14
15
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 13

def port
  @port
end

Instance Method Details

#configObject

A cached ElastiCache::ConfigResponse



38
39
40
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 38

def config
  @config ||= ConfigCommand.new(@host, @port, @timeout, ssl_context: @ssl_context).response
end

#engine_versionObject

The memcached engine version



43
44
45
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 43

def engine_version
  stats.engine_version
end

#parse_endpoint_address(addr) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 25

def parse_endpoint_address(addr)
  m = ENDPOINT_REGEX.match(addr)
  raise ArgumentError, "Unable to parse configuration endpoint address - #{addr}" unless m

  [m[1], (m[2] || DEFAULT_PORT).to_i]
end

#statsObject

A cached ElastiCache::StatsResponse



33
34
35
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 33

def stats
  @stats ||= StatsCommand.new(@host, @port, @timeout, ssl_context: @ssl_context).response
end