Class: Dalli::ElastiCache
- Inherits:
-
Object
- Object
- Dalli::ElastiCache
- 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
- DEFAULT_TIMEOUT =
5- VERSION =
'2.0.0'
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#client ⇒ Object
Dalli::Client configured to connect to the cluster’s nodes.
-
#engine_version ⇒ Object
The cache engine version of the cluster.
-
#initialize(config_endpoint, dalli_options = {}, timeout: DEFAULT_TIMEOUT) ⇒ ElastiCache
constructor
Creates a new Dalli::ElasticCache instance.
-
#refresh ⇒ Object
Clear all cached data from the cluster endpoint.
-
#servers ⇒ Object
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.
-
#version ⇒ Object
The number of times the cluster configuration has been changed.
Constructor Details
#initialize(config_endpoint, dalli_options = {}, timeout: DEFAULT_TIMEOUT) ⇒ 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, an IPv4 address, or a bracketed IPv6 address. dalli_options - a set of options passed to the Dalli::Client that is returned by the client method. Otherwise unused. timeout: - connect and read timeout in seconds for auto-discovery TCP calls. Defaults to 5 seconds.
41 42 43 44 45 |
# File 'lib/dalli/elasticache.rb', line 41 def initialize(config_endpoint, = {}, timeout: DEFAULT_TIMEOUT) @timeout = timeout @endpoint = Dalli::Elasticache::AutoDiscovery::Endpoint.new(config_endpoint, timeout:) @options = end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
27 28 29 |
# File 'lib/dalli/elasticache.rb', line 27 def endpoint @endpoint end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
27 28 29 |
# File 'lib/dalli/elasticache.rb', line 27 def @options end |
Instance Method Details
#client ⇒ Object
Dalli::Client configured to connect to the cluster’s nodes
48 49 50 |
# File 'lib/dalli/elasticache.rb', line 48 def client Dalli::Client.new(servers, ) end |
#engine_version ⇒ Object
The cache engine version of the cluster
Returns a string
62 63 64 |
# File 'lib/dalli/elasticache.rb', line 62 def engine_version endpoint.engine_version end |
#refresh ⇒ Object
Clear all cached data from the cluster endpoint
73 74 75 76 77 78 |
# File 'lib/dalli/elasticache.rb', line 73 def refresh config_endpoint = "#{endpoint.host}:#{endpoint.port}" @endpoint = Dalli::Elasticache::AutoDiscovery::Endpoint.new(config_endpoint, timeout: @timeout) self end |
#servers ⇒ Object
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
68 69 70 |
# File 'lib/dalli/elasticache.rb', line 68 def servers endpoint.config.nodes.map(&:to_s) end |
#version ⇒ Object
The number of times the cluster configuration has been changed
Returns an integer
55 56 57 |
# File 'lib/dalli/elasticache.rb', line 55 def version endpoint.config.version end |