Class: EventMachine::Hiredis::Connection

Inherits:
EM::Connection
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/em-hiredis/connection.rb

Instance Method Summary collapse

Methods included from EventEmitter

#emit, #listeners, #on, #remove_all_listeners, #remove_listener

Constructor Details

#initialize(host, port) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
# File 'lib/em-hiredis/connection.rb', line 7

def initialize(host, port)
  super
  @host, @port = host, port
  @name = "[em-hiredis #{@host}:#{@port}]"
end

Instance Method Details

#connection_completedObject



18
19
20
21
# File 'lib/em-hiredis/connection.rb', line 18

def connection_completed
  @reader = ::Hiredis::Reader.new
  emit(:connected)
end

#receive_data(data) ⇒ Object



23
24
25
26
27
28
# File 'lib/em-hiredis/connection.rb', line 23

def receive_data(data)
  @reader.feed(data)
  until (reply = @reader.gets) == false
    emit(:message, reply)
  end
end

#reconnect(host, port) ⇒ Object



13
14
15
16
# File 'lib/em-hiredis/connection.rb', line 13

def reconnect(host, port)
  super
  @host, @port = host, port
end

#send_command(command, args) ⇒ Object



34
35
36
# File 'lib/em-hiredis/connection.rb', line 34

def send_command(command, args)
  send_data(command(command, *args))
end

#to_sObject



38
39
40
# File 'lib/em-hiredis/connection.rb', line 38

def to_s
  @name
end

#unbindObject



30
31
32
# File 'lib/em-hiredis/connection.rb', line 30

def unbind
  emit(:closed)
end