Class: Redic::Client
- Inherits:
-
Object
- Object
- Redic::Client
- Defined in:
- lib/redic/client.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #configure(url, timeout) ⇒ Object
- #connect ⇒ Object
-
#initialize(url, timeout) ⇒ Client
constructor
A new instance of Client.
- #read ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(url, timeout) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/redic/client.rb', line 8 def initialize(url, timeout) @semaphore = Mutex.new configure(url, timeout) end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/redic/client.rb', line 6 def timeout @timeout end |
Instance Method Details
#configure(url, timeout) ⇒ Object
13 14 15 16 17 |
# File 'lib/redic/client.rb', line 13 def configure(url, timeout) @uri = URI.parse(url) @timeout = timeout @connection = nil end |
#connect ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/redic/client.rb', line 27 def connect establish_connection unless connected? @semaphore.synchronize do yield end rescue Errno::ECONNRESET @connection = nil retry end |
#read ⇒ Object
19 20 21 |
# File 'lib/redic/client.rb', line 19 def read @connection.read end |
#write(command) ⇒ Object
23 24 25 |
# File 'lib/redic/client.rb', line 23 def write(command) @connection.write(command) end |