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.



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

def timeout
  @timeout
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


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

def connected?
  @connected
end

#connection_completedObject



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

def connection_completed
  @connected = true
  succeed
end

#post_initObject



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

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

#readObject



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

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

#receive_data(data) ⇒ Object



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

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



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

def send(data)
  callback { send_data data }
end

#unbindObject



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

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