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
- #connected? ⇒ Boolean
- #disconnect! ⇒ Object
-
#initialize(url, timeout) ⇒ Client
constructor
A new instance of Client.
- #quit ⇒ Object
- #read ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(url, timeout) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/redic/client.rb', line 8 def initialize(url, timeout) @semaphore = Mutex.new @connection = false 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
15 16 17 18 19 20 |
# File 'lib/redic/client.rb', line 15 def configure(url, timeout) disconnect! @uri = URI.parse(url) @timeout = timeout end |
#connect ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/redic/client.rb', line 30 def connect establish_connection unless connected? @semaphore.synchronize do yield end rescue Errno::ECONNRESET @connection = false retry end |
#connected? ⇒ Boolean
41 42 43 |
# File 'lib/redic/client.rb', line 41 def connected? @connection && @connection.connected? end |
#disconnect! ⇒ Object
45 46 47 48 49 50 |
# File 'lib/redic/client.rb', line 45 def disconnect! if connected? @connection.disconnect @connection = false end end |
#quit ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/redic/client.rb', line 52 def quit if connected? assert_ok(call("QUIT")) disconnect! true else false end end |
#read ⇒ Object
22 23 24 |
# File 'lib/redic/client.rb', line 22 def read @connection.read end |
#write(command) ⇒ Object
26 27 28 |
# File 'lib/redic/client.rb', line 26 def write(command) @connection.write(command) end |