Class: Redis::Connection::RedisClient

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

Instance Method Summary collapse

Instance Method Details

#connection_completedObject



16
17
18
# File 'lib/redis/connection/synchrony.rb', line 16

def connection_completed
  succeed
end

#post_initObject



11
12
13
14
# File 'lib/redis/connection/synchrony.rb', line 11

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

#readObject



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

def read
  @req = EventMachine::DefaultDeferrable.new
  EventMachine::Synchrony.sync @req
end

#receive_data(data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/redis/connection/synchrony.rb', line 20

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

  begin
    until (reply = @reader.gets) == false
      @req.succeed [:reply, reply]
    end
  rescue RuntimeError => err
    @req.fail [:error, ::Redis::ProtocolError.new(err.message)]
  end
end

#send(data) ⇒ Object



37
38
39
# File 'lib/redis/connection/synchrony.rb', line 37

def send(data)
  callback { send_data data }
end

#unbindObject



41
42
43
44
45
46
47
48
# File 'lib/redis/connection/synchrony.rb', line 41

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