Class: Redis::Connection::RedisClient

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/redis/connection/synchrony.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



20
21
22
# File 'lib/redis/connection/synchrony.rb', line 20

def timeout
  @timeout
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/redis/connection/synchrony.rb', line 33

def connected?
  @connected
end

#connection_completedObject



28
29
30
31
# File 'lib/redis/connection/synchrony.rb', line 28

def connection_completed
  @connected = true
  succeed
end

#post_initObject



22
23
24
25
26
# File 'lib/redis/connection/synchrony.rb', line 22

def post_init
  @req = nil
  @connected = false
  @reader = ::Hiredis::Reader.new
end

#readObject



55
56
57
58
59
# File 'lib/redis/connection/synchrony.rb', line 55

def read
  @req = EventMachine::DefaultDeferrable.new
  @req.timeout(@timeout, :timeout) if @timeout > 0
  EventMachine::Synchrony.sync @req
end

#receive_data(data) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/redis/connection/synchrony.rb', line 37

def receive_data(data)
  @reader.feed(data)

  loop do
    begin
      reply = @reader.gets
    rescue RuntimeError => err
      @req.fail [:error, ProtocolError.new(err.message)]
      break
    end

    break if reply == false

    reply = CommandError.new(reply.message) if reply.is_a?(RuntimeError)
    @req.succeed [:reply, reply]
  end
end

#send(data) ⇒ Object



61
62
63
# File 'lib/redis/connection/synchrony.rb', line 61

def send(data)
  callback { send_data data }
end

#unbindObject



65
66
67
68
69
70
71
72
73
# File 'lib/redis/connection/synchrony.rb', line 65

def unbind
  @connected = false
  if @req
    @req.fail [:error, Errno::ECONNRESET]
    @req = nil
  else
    fail
  end
end