Class: EventMachine::Hiredis::Connection
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- EventMachine::Hiredis::Connection
show all
- Includes:
- EventEmitter
- Defined in:
- lib/em-hiredis/connection.rb
Instance Method Summary
collapse
#emit, #listeners, #on, #remove_all_listeners, #remove_listener
Constructor Details
#initialize(host, port, tls = false) ⇒ Connection
Returns a new instance of Connection.
7
8
9
10
11
|
# File 'lib/em-hiredis/connection.rb', line 7
def initialize(host, port, tls = false)
super
@host, @port, @tls = host, port, tls
@name = "[em-hiredis #{@host}:#{@port} tls:#{@tls}]"
end
|
Instance Method Details
#connection_completed ⇒ Object
18
19
20
21
22
23
|
# File 'lib/em-hiredis/connection.rb', line 18
def connection_completed
@reader = ::Hiredis::Reader.new
tls_options = @tls == true ? { ssl_version: :tlsv1_2 } : @tls
start_tls(tls_options) if tls_options
emit(:connected)
end
|
#receive_data(data) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/em-hiredis/connection.rb', line 25
def receive_data(data)
@reader.feed(data)
until (reply = @reader.gets) == false
emit(:message, reply)
end
end
|
#reconnect(host, port, tls = false) ⇒ Object
13
14
15
16
|
# File 'lib/em-hiredis/connection.rb', line 13
def reconnect(host, port, tls = false)
super(host, port)
@host, @port, @tls = host, port, tls
end
|
#send_command(command, args) ⇒ Object
36
37
38
|
# File 'lib/em-hiredis/connection.rb', line 36
def send_command(command, args)
send_data(command(command, *args))
end
|
#to_s ⇒ Object
40
41
42
|
# File 'lib/em-hiredis/connection.rb', line 40
def to_s
@name
end
|
#unbind ⇒ Object
32
33
34
|
# File 'lib/em-hiredis/connection.rb', line 32
def unbind
emit(:closed)
end
|