File tree Expand file tree Collapse file tree 5 files changed +10
-36
lines changed Expand file tree Collapse file tree 5 files changed +10
-36
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ def initialize(options = {})
77
77
@connection = nil
78
78
@command_map = { }
79
79
80
+ @pending_reads = 0
81
+
80
82
if options . include? ( :sentinels )
81
83
@connector = Connector ::Sentinel . new ( @options )
82
84
else
@@ -243,12 +245,15 @@ def io
243
245
244
246
def read
245
247
io do
246
- connection . read
248
+ value = connection . read
249
+ @pending_reads -= 1
250
+ value
247
251
end
248
252
end
249
253
250
254
def write ( command )
251
255
io do
256
+ @pending_reads += 1
252
257
connection . write ( command )
253
258
end
254
259
end
@@ -315,6 +320,7 @@ def establish_connection
315
320
@options [ :port ] = server [ :port ]
316
321
317
322
@connection = @options [ :driver ] . connect ( server )
323
+ @pending_reads = 0
318
324
rescue TimeoutError ,
319
325
Errno ::ECONNREFUSED ,
320
326
Errno ::EHOSTDOWN ,
@@ -326,6 +332,8 @@ def establish_connection
326
332
end
327
333
328
334
def ensure_connected
335
+ disconnect if @pending_reads > 0
336
+
329
337
attempts = 0
330
338
331
339
begin
@@ -342,10 +350,7 @@ def ensure_connected
342
350
connect
343
351
end
344
352
345
- connection . use { yield }
346
- rescue ConnectionCorruptedError
347
- disconnect
348
- retry
353
+ yield
349
354
rescue BaseConnectionError
350
355
disconnect
351
356
Original file line number Diff line number Diff line change @@ -56,10 +56,6 @@ def read
56
56
rescue RuntimeError => err
57
57
raise ProtocolError . new ( err . message )
58
58
end
59
-
60
- def use
61
- yield
62
- end
63
59
end
64
60
end
65
61
end
Original file line number Diff line number Diff line change @@ -246,7 +246,6 @@ def get_tcp_keepalive
246
246
247
247
def initialize ( sock )
248
248
@sock = sock
249
- @pending_reads = 0
250
249
end
251
250
252
251
def connected?
@@ -267,7 +266,6 @@ def timeout=(timeout)
267
266
end
268
267
269
268
def write ( command )
270
- @pending_reads += 1
271
269
@sock . write ( build_command ( command ) )
272
270
end
273
271
@@ -292,22 +290,18 @@ def format_reply(reply_type, line)
292
290
end
293
291
294
292
def format_error_reply ( line )
295
- @pending_reads -= 1
296
293
CommandError . new ( line . strip )
297
294
end
298
295
299
296
def format_status_reply ( line )
300
- @pending_reads -= 1
301
297
line . strip
302
298
end
303
299
304
300
def format_integer_reply ( line )
305
- @pending_reads -= 1
306
301
line . to_i
307
302
end
308
303
309
304
def format_bulk_reply ( line )
310
- @pending_reads -= 1
311
305
bulklen = line . to_i
312
306
return if bulklen == -1
313
307
reply = encode ( @sock . read ( bulklen ) )
@@ -317,20 +311,10 @@ def format_bulk_reply(line)
317
311
318
312
def format_multi_bulk_reply ( line )
319
313
n = line . to_i
320
-
321
- @pending_reads += n
322
-
323
314
return if n == -1
324
315
325
- @pending_reads -= 1
326
-
327
316
Array . new ( n ) { read }
328
317
end
329
-
330
- def use
331
- raise ConnectionCorruptedError if @pending_reads > 0
332
- yield
333
- end
334
318
end
335
319
end
336
320
end
Original file line number Diff line number Diff line change @@ -117,10 +117,6 @@ def read
117
117
raise "Unknown type #{ type . inspect } "
118
118
end
119
119
end
120
-
121
- def use
122
- yield
123
- end
124
120
end
125
121
end
126
122
end
Original file line number Diff line number Diff line change @@ -37,11 +37,4 @@ class TimeoutError < BaseConnectionError
37
37
# Raised when the connection was inherited by a child process.
38
38
class InheritedError < BaseConnectionError
39
39
end
40
-
41
- # Raised when the connection is left in an inconsistent state
42
- # due to timeout issues. See issue #501.
43
- #
44
- # Only used internally.
45
- class ConnectionCorruptedError < BaseConnectionError
46
- end
47
40
end
You can’t perform that action at this time.
0 commit comments