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
# File 'lib/em-hiredis/connection.rb', line 7

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

Instance Method Details

#connection_completedObject



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

def connection_completed
  EM::Hiredis.logger.debug("#{to_s}: connection open")
  @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



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

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

#send_command(sym, *args) ⇒ Object



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

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

#to_sObject



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

def to_s
  "Redis connection #{@host}:#{@port}"
end

#unbindObject



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

def unbind
  EM::Hiredis.logger.debug("#{to_s}: connection unbound")
  emit(:closed)
end