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 Strings like “my-host.cache.aws.com:11211”

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr) ⇒ Endpoint

Returns a new instance of Endpoint.


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

def initialize(addr)
  @host, @port = parse_endpoint_address(addr)
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


36
37
38
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 36

def config
  @config ||= ConfigCommand.new(@host, @port, engine_version).response
end

#engine_versionObject

The memcached engine version


41
42
43
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 41

def engine_version
  stats.engine_version
end

#parse_endpoint_address(addr) ⇒ Object

Raises:

  • (ArgumentError)

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

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


31
32
33
# File 'lib/dalli/elasticache/auto_discovery/endpoint.rb', line 31

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