Class: Redic::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redic/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  @uri = URI.parse(url)
  @timeout = timeout
  @connection = nil
  @semaphore = Mutex.new
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout


6
7
8
# File 'lib/redic/client.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#connectObject


23
24
25
26
27
28
29
30
31
32
# File 'lib/redic/client.rb', line 23

def connect
  establish_connection unless connected?

  @semaphore.synchronize do
    yield
  end
rescue Errno::ECONNRESET
  @connection = nil
  retry
end

#readObject


15
16
17
# File 'lib/redic/client.rb', line 15

def read
  @connection.read
end

#write(command) ⇒ Object


19
20
21
# File 'lib/redic/client.rb', line 19

def write(command)
  @connection.write(command)
end