Class: Redis::Connection::RedisClient
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Redis::Connection::RedisClient
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/redis/connection/synchrony.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #connection_completed ⇒ Object
- #post_init ⇒ Object
- #read ⇒ Object
- #receive_data(data) ⇒ Object
- #send(data) ⇒ Object
- #unbind ⇒ Object
Instance Attribute Details
#timeout ⇒ Object
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
32 33 34 |
# File 'lib/redis/connection/synchrony.rb', line 32 def connected? @connected end |
#connection_completed ⇒ Object
27 28 29 30 |
# File 'lib/redis/connection/synchrony.rb', line 27 def connection_completed @connected = true succeed end |
#post_init ⇒ Object
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 |
#read ⇒ Object
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.)] break end break if reply == false reply = CommandError.new(reply.) 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 |
#unbind ⇒ Object
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 |