Class: Dalli::Elasticache::AutoDiscovery::ConfigResponse
- Inherits:
-
Object
- Object
- Dalli::Elasticache::AutoDiscovery::ConfigResponse
- Defined in:
- lib/dalli/elasticache/auto_discovery/config_response.rb
Overview
This class wraps the raw ASCII response from an Auto Discovery endpoint and provides methods for extracting data from that response.
docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.AddingToYourClientLibrary.html
Constant Summary collapse
- VERSION_REGEX =
Matches the version line of the response
/^(\d+)\r?\n/.freeze
- NODE_REGEX =
Matches strings like “my-cluster.001.cache.aws.com|10.154.182.29|11211”
/(([-.a-zA-Z0-9]+)\|(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\|(\d+))/.freeze
- NODE_LIST_REGEX =
/^(#{NODE_REGEX}\s*)+$/.freeze
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
The raw response text.
Instance Method Summary collapse
-
#initialize(response_text) ⇒ ConfigResponse
constructor
A new instance of ConfigResponse.
-
#nodes ⇒ Object
Node hosts, ip addresses, and ports.
-
#version ⇒ Object
The number of times the configuration has been changed.
Constructor Details
#initialize(response_text) ⇒ ConfigResponse
Returns a new instance of ConfigResponse.
21 22 23 |
# File 'lib/dalli/elasticache/auto_discovery/config_response.rb', line 21 def initialize(response_text) @text = response_text.to_s end |
Instance Attribute Details
#text ⇒ Object (readonly)
The raw response text
12 13 14 |
# File 'lib/dalli/elasticache/auto_discovery/config_response.rb', line 12 def text @text end |
Instance Method Details
#nodes ⇒ Object
Node hosts, ip addresses, and ports
Returns an Array of Hashes with values for :host, :ip and :port
38 39 40 41 42 |
# File 'lib/dalli/elasticache/auto_discovery/config_response.rb', line 38 def nodes NODE_LIST_REGEX.match(@text).to_s.scan(NODE_REGEX).map do |match| Node.new(match[1], match[2], match[3].to_i) end end |
#version ⇒ Object
The number of times the configuration has been changed
Returns an integer
28 29 30 31 32 33 |
# File 'lib/dalli/elasticache/auto_discovery/config_response.rb', line 28 def version m = VERSION_REGEX.match(@text) return -1 unless m m[1].to_i end |