Class: Redis2::Connection::Hiredis
- Inherits:
-
Object
- Object
- Redis2::Connection::Hiredis
- Defined in:
- lib/redis2/connection/hiredis.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(connection) ⇒ Hiredis
constructor
A new instance of Hiredis.
- #read ⇒ Object
- #timeout=(timeout) ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Hiredis
Returns a new instance of Hiredis.
26 27 28 |
# File 'lib/redis2/connection/hiredis.rb', line 26 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 |
# File 'lib/redis2/connection/hiredis.rb', line 10 def self.connect(config) connection = ::Hiredis::Connection.new if config[:scheme] == "unix" connection.connect_unix(config[:path], Integer(config[:timeout] * 1_000_000)) else connection.connect(config[:host], config[:port], Integer(config[:timeout] * 1_000_000)) end instance = new(connection) instance.timeout = config[:timeout] instance rescue Errno::ETIMEDOUT raise TimeoutError end |
Instance Method Details
#connected? ⇒ Boolean
30 31 32 |
# File 'lib/redis2/connection/hiredis.rb', line 30 def connected? @connection && @connection.connected? end |
#disconnect ⇒ Object
39 40 41 42 |
# File 'lib/redis2/connection/hiredis.rb', line 39 def disconnect @connection.disconnect @connection = nil end |
#read ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/redis2/connection/hiredis.rb', line 50 def read reply = @connection.read 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
34 35 36 37 |
# File 'lib/redis2/connection/hiredis.rb', line 34 def timeout=(timeout) # Hiredis works with microsecond timeouts @connection.timeout = Integer(timeout * 1_000_000) end |
#write(command) ⇒ Object
44 45 46 47 48 |
# File 'lib/redis2/connection/hiredis.rb', line 44 def write(command) @connection.write(command.flatten(1)) rescue Errno::EAGAIN raise TimeoutError end |