Skip to content

Commit cfc6b1b

Browse files
committed
Push the connected status tracking into the EM::Connection so the status
can be properly tracked.
1 parent 38ca0f2 commit cfc6b1b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/redis/connection/synchrony.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ class RedisClient < EventMachine::Connection
1010

1111
def post_init
1212
@req = nil
13+
@connected = false
1314
@reader = ::Hiredis::Reader.new
1415
end
1516

1617
def connection_completed
18+
@connected = true
1719
succeed
1820
end
1921

22+
def connected?
23+
@connected
24+
end
25+
2026
def receive_data(data)
2127
@reader.feed(data)
2228

@@ -39,6 +45,7 @@ def send(data)
3945
end
4046

4147
def unbind
48+
@connected = false
4249
if @req
4350
@req.fail [:error, Errno::ECONNRESET]
4451
@req = nil
@@ -53,12 +60,11 @@ class Synchrony
5360

5461
def initialize
5562
@timeout = 5_000_000
56-
@state = :disconnected
5763
@connection = nil
5864
end
5965

6066
def connected?
61-
@state == :connected
67+
@connection && @connection.connected?
6268
end
6369

6470
def timeout=(usecs)
@@ -79,7 +85,6 @@ def connect_unix(path, timeout)
7985
end
8086

8187
def disconnect
82-
@state = :disconnected
8388
@connection.close_connection
8489
@connection = nil
8590
end
@@ -105,7 +110,6 @@ def read
105110
def setup_connect_callbacks(conn, f)
106111
conn.callback do
107112
@connection = conn
108-
@state = :connected
109113
f.resume conn
110114
end
111115

0 commit comments

Comments
 (0)