Class: Dalli::ElastiCache

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

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ElastiCache.



12
13
14
15
16
# File 'lib/dalli/elasticache.rb', line 12

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

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



10
11
12
# File 'lib/dalli/elasticache.rb', line 10

def endpoint
  @endpoint
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/dalli/elasticache.rb', line 10

def options
  @options
end

Instance Method Details

#clientObject

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



19
20
21
# File 'lib/dalli/elasticache.rb', line 19

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

#engine_versionObject

The cache engine version of the cluster



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

def engine_version
  endpoint.engine_version
end

#refreshObject

Clear all cached data from the cluster endpoint



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

def refresh
  config_endpoint = "#{endpoint.host}:#{endpoint.port}"
  @endpoint = Dalli::Elasticache::AutoDiscovery::Endpoint.new(config_endpoint, endpoint.timeout)
  
  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



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

def servers
  endpoint.config.nodes.map{ |h| "#{h[:host]}:#{h[:port]}" }
end

#versionObject

The number of times the cluster configuration has been changed

Returns an integer



26
27
28
# File 'lib/dalli/elasticache.rb', line 26

def version
  endpoint.config.version
end