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
# File 'lib/redic/client.rb', line 8

def initialize(url, timeout)
  @semaphore = Mutex.new
  configure(url, timeout)
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

#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

#connectObject



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

#readObject



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