Skip to content

Commit f96e46b

Browse files
committed
mostly fixes redis#456. there's still an issue w/ hiredis and multi-bulk replies
1 parent 8a49069 commit f96e46b

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

redis/client.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,12 +2257,15 @@ def immediate_execute_command(self, *args, **options):
22572257
except ConnectionError:
22582258
conn.disconnect()
22592259
# if we're not already watching, we can safely retry the command
2260-
# assuming it was a connection timeout
2261-
if not self.watching:
2262-
conn.send_command(*args)
2263-
return self.parse_response(conn, command_name, **options)
2264-
self.reset()
2265-
raise
2260+
try:
2261+
if not self.watching:
2262+
conn.send_command(*args)
2263+
return self.parse_response(conn, command_name, **options)
2264+
except ConnectionError:
2265+
# the retry failed so cleanup.
2266+
conn.disconnect()
2267+
self.reset()
2268+
raise
22662269

22672270
def pipeline_execute_command(self, *args, **options):
22682271
"""

tests/test_connection_pool.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,34 @@ def test_busy_loading_disconnects_socket(self, r):
187187
pool = r.connection_pool
188188
assert len(pool._available_connections) == 1
189189
assert not pool._available_connections[0]._sock
190+
191+
@skip_if_server_version_lt('2.8.8')
192+
def test_busy_loading_from_pipeline_immediate_command(self, r):
193+
"""
194+
BusyLoadingErrors should raise from Pipelines that execute a
195+
command immediately, like WATCH does.
196+
"""
197+
pipe = r.pipeline()
198+
with pytest.raises(redis.BusyLoadingError):
199+
pipe.immediate_execute_command('DEBUG', 'ERROR',
200+
'LOADING fake message')
201+
pool = r.connection_pool
202+
assert not pipe.connection
203+
assert len(pool._available_connections) == 1
204+
assert not pool._available_connections[0]._sock
205+
206+
# TODO: This fails on hiredis. need to think about this
207+
# @skip_if_server_version_lt('2.8.8')
208+
# def test_busy_loading_from_pipeline(self, r):
209+
# """
210+
# BusyLoadingErrors should be raised from a pipeline execution
211+
# regardless of the raise_on_error flag.
212+
# """
213+
# pipe = r.pipeline()
214+
# pipe.execute_command('DEBUG', 'ERROR', 'LOADING fake message')
215+
# with pytest.raises(redis.BusyLoadingError):
216+
# pipe.execute()
217+
# pool = r.connection_pool
218+
# assert not pipe.connection
219+
# assert len(pool._available_connections) == 1
220+
# assert not pool._available_connections[0]._sock

0 commit comments

Comments
 (0)