class Redis::Connection::RedisClient

def connected?

def connected?
  @connected
end

def connection_completed

def connection_completed
  @connected = true
  succeed
end

def post_init

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

def read

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

def receive_data(data)

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

def send(data)

def send(data)
  callback { send_data data }
end

def unbind

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