Class: Dalli::ElastiCache
- Inherits:
-
Object
- Object
- Dalli::ElastiCache
- Defined in:
- lib/dalli/elasticache.rb,
lib/dalli/elasticache/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#config_host ⇒ Object
Returns the value of attribute config_host.
-
#config_port ⇒ Object
Returns the value of attribute config_port.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #client ⇒ Object
- #config_get_cluster ⇒ Object
- #data ⇒ Object
-
#initialize(config_endpoint, options = {}) ⇒ ElastiCache
constructor
A new instance of ElastiCache.
- #refresh ⇒ Object
- #servers ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(config_endpoint, options = {}) ⇒ ElastiCache
Returns a new instance of ElastiCache.
9 10 11 12 13 14 |
# File 'lib/dalli/elasticache.rb', line 9 def initialize(config_endpoint, ={}) @config_host, @config_port = config_endpoint.split(':') @config_port ||= 11211 @options = end |
Instance Attribute Details
#config_host ⇒ Object
Returns the value of attribute config_host.
7 8 9 |
# File 'lib/dalli/elasticache.rb', line 7 def config_host @config_host end |
#config_port ⇒ Object
Returns the value of attribute config_port.
7 8 9 |
# File 'lib/dalli/elasticache.rb', line 7 def config_port @config_port end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/dalli/elasticache.rb', line 7 def @options end |
Instance Method Details
#client ⇒ Object
16 17 18 |
# File 'lib/dalli/elasticache.rb', line 16 def client Dalli::Client.new(servers, ) end |
#config_get_cluster ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dalli/elasticache.rb', line 28 def config_get_cluster # TODO: handle timeouts s = TCPSocket.new(config_host, config_port) s.puts "config get cluster\r\n" data = [] while (line = s.gets) != "END\r\n" data << line end s.close data end |
#data ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dalli/elasticache.rb', line 41 def data return @data if @data raw_data = config_get_cluster version = raw_data[1].to_i instance_data = raw_data[2].split(/\s+/) instances = instance_data.map{ |raw| host, ip, port = raw.split('|'); {:host => host, :ip => ip, :port => port} } @data = { :version => version, :instances => instances } end |
#refresh ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/dalli/elasticache.rb', line 20 def refresh # Reset data @data = nil data self end |
#servers ⇒ Object
54 55 56 |
# File 'lib/dalli/elasticache.rb', line 54 def servers data[:instances].map{ |i| "#{i[:ip]}:#{i[:port]}" } end |
#version ⇒ Object
50 51 52 |
# File 'lib/dalli/elasticache.rb', line 50 def version data[:version] end |