Class: Rlite::Connection::Hirlite
- Inherits:
-
Object
- Object
- Rlite::Connection::Hirlite
- Defined in:
- lib/hirlite/connection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(connection) ⇒ Hirlite
constructor
A new instance of Hirlite.
- #read ⇒ Object
- #timeout=(timeout) ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Hirlite
Returns a new instance of Hirlite.
27 28 29 |
# File 'lib/hirlite/connection.rb', line 27 def initialize(connection) @connection = connection end |
Class Method Details
.connect(config) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hirlite/connection.rb', line 10 def self.connect(config) connection = ::Hirlite::Rlite.new connect_timeout = (config.fetch(:connect_timeout, 0) * 1_000_000).to_i if config[:scheme] == "unix" connection.connect_unix(config[:path], connect_timeout) else connection.connect(config[:host], config[:port], connect_timeout) end instance = new(connection) instance.timeout = config[:timeout] instance rescue Errno::ETIMEDOUT raise TimeoutError end |
Instance Method Details
#connected? ⇒ Boolean
31 32 33 |
# File 'lib/hirlite/connection.rb', line 31 def connected? @connection && @connection.connected? end |
#disconnect ⇒ Object
40 41 42 43 |
# File 'lib/hirlite/connection.rb', line 40 def disconnect @connection.disconnect @connection = nil end |
#read ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hirlite/connection.rb', line 51 def read reply = @connection.read if reply == nil write(['__rlite_poll']) reply = @connection.read end reply = CommandError.new(reply.) if reply.is_a?(RuntimeError) reply rescue Errno::EAGAIN raise TimeoutError rescue RuntimeError => err raise ProtocolError.new(err.) end |
#timeout=(timeout) ⇒ Object
35 36 37 38 |
# File 'lib/hirlite/connection.rb', line 35 def timeout=(timeout) # Hirlite works with microsecond timeouts @connection.timeout = Integer(timeout * 1_000_000) end |
#write(command) ⇒ Object
45 46 47 48 49 |
# File 'lib/hirlite/connection.rb', line 45 def write(command) @connection.write(command.flatten(1)) rescue Errno::EAGAIN raise TimeoutError end |