21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/redis/event_machine.rb', line 21
def connect_to(host,port)
log("Redis >> Using EM connection")
sock = Thread.current[fiber_key]
return @sock if @sock and not @sock.closed?
Thread.current[fiber_key] = nil
Thread.current[fiber_key] ||= begin
@sock = EM::SocketConnection.connect(host, port, @timeout)
yielding = true
fiber = Fiber.current
@sock.callback do
log("Redis >> Connected")
@status = 'CONNECTED'
@retry = nil
yielding = false
fiber.resume if Fiber.current != fiber
log("Redis >> Done with callback")
end
@sock.errback do
@sock = nil
yielding = false
fiber.resume if Fiber.current != fiber
end
Fiber.yield if yielding
@sock
end
end
|