Class: Dalli::ElastiCache

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/elasticache.rb,
lib/dalli/elasticache/version.rb

Overview

Dalli::Elasticache provides an interface for providing a configuration endpoint for a memcached cluster on ElasticCache and retrieving the list of addresses (hostname and port) for the individual nodes of that cluster.

This allows the caller to pass that server list to Dalli, which then distributes cached items consistently over the nodes.

Constant Summary collapse

VERSION =
'1.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_endpoint, dalli_options = {}) ⇒ ElastiCache

Creates a new Dalli::ElasticCache instance.

config_endpoint - a String containing the host and (optionally) port of the configuration endpoint for the cluster. If not specified the port will default to 11211. The host must be either a DNS name or an IPv4 address. IPv6 addresses are not handled at this time. dalli_options - a set of options passed to the Dalli::Client that is returned by the client method. Otherwise unused.


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

def initialize(config_endpoint, dalli_options = {})
  @endpoint = Dalli::Elasticache::AutoDiscovery::Endpoint.new(config_endpoint)
  @options = dalli_options
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.


24
25
26
# File 'lib/dalli/elasticache.rb', line 24

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.


24
25
26
# File 'lib/dalli/elasticache.rb', line 24

def options
  @options
end

Instance Method Details

#clientObject

Dalli::Client configured to connect to the cluster's nodes


42
43
44
# File 'lib/dalli/elasticache.rb', line 42

def client
  Dalli::Client.new(servers, options)
end

#engine_versionObject

The cache engine version of the cluster

Returns a string


56
57
58
# File 'lib/dalli/elasticache.rb', line 56

def engine_version
  endpoint.engine_version
end

#refreshObject

Clear all cached data from the cluster endpoint


67
68
69
70
71
72
# File 'lib/dalli/elasticache.rb', line 67

def refresh
  config_endpoint = "#{endpoint.host}:#{endpoint.port}"
  @endpoint = Dalli::Elasticache::AutoDiscovery::Endpoint.new(config_endpoint)

  self
end

#serversObject

List of cluster server nodes with ip addresses and ports Always use host name instead of private elasticache IPs as internal IPs can change after a node is rebooted


62
63
64
# File 'lib/dalli/elasticache.rb', line 62

def servers
  endpoint.config.nodes.map(&:to_s)
end

#versionObject

The number of times the cluster configuration has been changed

Returns an integer


49
50
51
# File 'lib/dalli/elasticache.rb', line 49

def version
  endpoint.config.version
end