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
timeoutbounds the entire multi-line read as a single wall-clock deadline, not each individualreadline. -
#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.
16 17 18 19 20 21 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 16 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.
14 15 16 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 14 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
14 15 16 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 14 def port @port end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
14 15 16 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 14 def ssl_context @ssl_context end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 14 def timeout @timeout end |
Instance Method Details
#response_from_socket(socket) ⇒ Object
timeout bounds the entire multi-line read as a single wall-clock deadline,
not each individual readline. A per-line readiness check (e.g. wait_readable)
can't tell buffered-but-unread bytes apart from an empty socket once a buffering
layer (Ruby's IO buffer, or OpenSSL::Buffering for TLS) sits between the fd and
readline, so it can't be used to gate individual lines reliably.
42 43 44 45 46 47 48 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 42 def response_from_socket(socket) return read_lines(socket) unless timeout Timeout.timeout(timeout, Timeout::Error, "Auto discovery read timed out after #{timeout}s") do read_lines(socket) end end |
#send_command ⇒ Object
Send an ASCII command to the endpoint
Returns the raw response as a String
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dalli/elasticache/auto_discovery/base_command.rb', line 26 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 |