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.
-
#ssl_context ⇒ Object
readonly
Returns the value of attribute ssl_context.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(host, port, timeout = nil, ssl_context: nil) ⇒ 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, timeout = nil, ssl_context: nil) ⇒ BaseCommand
Returns a new instance of BaseCommand.
15 16 17 18 19 20 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 15 def initialize(host, port, timeout = nil, ssl_context: nil) @host = host @port = port @timeout = timeout @ssl_context = ssl_context end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 13 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 13 def port @port end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
13 14 15 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 13 def ssl_context @ssl_context end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
13 14 15 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 13 def timeout @timeout end |
Instance Method Details
#response_from_socket(socket) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 36 def response_from_socket(socket) data = +'' loop do wait_for_data(socket) line = socket.readline break if line.include?('END') data << line end data end |
#send_command ⇒ Object
Send an ASCII command to the endpoint
Returns the raw response as a String
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 25 def send_command tcp_socket = ::Socket.tcp(@host, @port, connect_timeout: timeout) begin socket = ssl_context ? wrap_with_ssl(tcp_socket) : tcp_socket socket.puts command response_from_socket(socket) ensure (socket || tcp_socket).close end end |