Class: Redis::Connection::ThreadsafeHiredis
- Inherits:
-
Object
- Object
- Redis::Connection::ThreadsafeHiredis
- Defined in:
- lib/hiredis/thread_safe_connection_redisrb_driver.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(connection) ⇒ ThreadsafeHiredis
constructor
A new instance of ThreadsafeHiredis.
- #read ⇒ Object
- #timeout=(timeout) ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(connection) ⇒ ThreadsafeHiredis
Returns a new instance of ThreadsafeHiredis.
27 28 29 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 27 def initialize(connection) @connection = connection end |
Class Method Details
.connect(config) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 11 def self.connect(config) connection = ::Hiredis::ThreadSafeConnection.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
31 32 33 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 31 def connected? @connection && @connection.connected? end |
#disconnect ⇒ Object
40 41 42 43 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 40 def disconnect @connection.disconnect @connection = nil end |
#read ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 51 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
35 36 37 38 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 35 def timeout=(timeout) # Hiredis works with microsecond timeouts @connection.timeout = Integer(timeout * 1_000_000) end |
#write(command) ⇒ Object
45 46 47 48 49 |
# File 'lib/hiredis/thread_safe_connection_redisrb_driver.rb', line 45 def write(command) @connection.write(command.flatten(1)) rescue Errno::EAGAIN raise TimeoutError end |