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

#connected?Boolean

Returns:

  • (Boolean)


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

def connected?
  @connected
end

#connection_completedObject



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

def connection_completed
  @connected = true
  succeed
end

#post_initObject



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

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

#readObject



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

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

#receive_data(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redis/connection/synchrony.rb', line 26

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



43
44
45
# File 'lib/redis/connection/synchrony.rb', line 43

def send(data)
  callback { send_data data }
end

#unbindObject



47
48
49
50
51
52
53
54
55
# File 'lib/redis/connection/synchrony.rb', line 47

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