Class: Dalli::Elasticache::AutoDiscovery::BaseCommand
- Inherits:
-
Object
- Object
- Dalli::Elasticache::AutoDiscovery::BaseCommand
- Defined in:
- lib/dalli/elasticache/auto_discovery/base_command.rb
Overview
Base command class for configuration endpoint command. Contains the network logic.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(host, port) ⇒ BaseCommand
constructor
A new instance of BaseCommand.
- #response_from_socket(socket) ⇒ Object
-
#send_command ⇒ Object
Send an ASCII command to the endpoint.
Constructor Details
#initialize(host, port) ⇒ BaseCommand
Returns a new instance of BaseCommand.
13 14 15 16 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 13 def initialize(host, port) @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 11 def port @port end |
Instance Method Details
#response_from_socket(socket) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 31 def response_from_socket(socket) data = +'' until (line = socket.readline).include?('END') data << line end data end |
#send_command ⇒ Object
Send an ASCII command to the endpoint
Returns the raw response as a String
21 22 23 24 25 26 27 28 29 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 21 def send_command socket = TCPSocket.new(@host, @port) begin socket.puts command response_from_socket(socket) ensure socket.close end end |