Class: Redis2::Connection::Redis2Client
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Redis2::Connection::Redis2Client
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/redis2/connection/synchrony.rb
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #connection_completed ⇒ Object
- #post_init ⇒ Object
- #read ⇒ Object
- #receive_data(data) ⇒ Object
- #send(data) ⇒ Object
- #unbind ⇒ Object
Instance Method Details
#connected? ⇒ Boolean
23 24 25 |
# File 'lib/redis2/connection/synchrony.rb', line 23 def connected? @connected end |
#connection_completed ⇒ Object
18 19 20 21 |
# File 'lib/redis2/connection/synchrony.rb', line 18 def connection_completed @connected = true succeed end |
#post_init ⇒ Object
12 13 14 15 16 |
# File 'lib/redis2/connection/synchrony.rb', line 12 def post_init @req = nil @connected = false @reader = ::Hiredis::Reader.new end |
#read ⇒ Object
45 46 47 48 |
# File 'lib/redis2/connection/synchrony.rb', line 45 def read @req = EventMachine::DefaultDeferrable.new EventMachine::Synchrony.sync @req end |
#receive_data(data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/redis2/connection/synchrony.rb', line 27 def receive_data(data) @reader.feed(data) loop do begin reply = @reader.gets rescue RuntimeError => err @req.fail [:error, ProtocolError.new(err.)] break end break if reply == false reply = CommandError.new(reply.) if reply.is_a?(RuntimeError) @req.succeed [:reply, reply] end end |
#send(data) ⇒ Object
50 51 52 |
# File 'lib/redis2/connection/synchrony.rb', line 50 def send(data) callback { send_data data } end |
#unbind ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/redis2/connection/synchrony.rb', line 54 def unbind @connected = false if @req @req.fail [:error, Errno::ECONNRESET] @req = nil else fail end end |