summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Anderson <b@banjiewen.net>2011-04-22 17:50:28 -0700
committerBenjamin Anderson <b@banjiewen.net>2011-04-22 17:50:28 -0700
commitb1651bab349004fffe6460f7fbb306ea6e2c4dc8 (patch)
treee33cee87cd518dd1d1a24971374420ebc052a3dd
parent2eb518a7c53702168f5e987c1741512ac5e9b4d7 (diff)
downloadredis-py-b1651bab349004fffe6460f7fbb306ea6e2c4dc8.tar.gz
Added socket disconnection if commands are rejected due to AOF/RDB load.
SELECT commands are issued only on initial socket connection. If a user issues a command during an AOF/RDB load, the socket connection will be successfully opened, but the SELECT command will be lost. If subsequent commands are sent after the AOF/RDB load is completed, the SELECT command will not be retried (due to the open socket), and those commands will go to the wrong DB. This behavior appears to be present in hiredis as well as redis-py. Fixing it here by special casing the AOF/RDB load message and closing the socket connection before raising ResponseError.
-rw-r--r--redis/connection.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/redis/connection.py b/redis/connection.py
index e317e85..85b4a7c 100644
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -97,6 +97,11 @@ class PythonConnection(BaseConnection):
if byte == '-':
if response.startswith('ERR '):
response = response[4:]
+ if response.startswith('LOADING '):
+ # If we're loading the dataset into memory, kill the socket
+ # so we re-initialize (and re-SELECT) next time.
+ self.disconnect()
+ response = response[8:]
raise ResponseError(response)
# single value
elif byte == '+':