summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2020-06-01 11:41:20 -0700
committerAndy McCurdy <andy@andymccurdy.com>2020-06-01 11:41:20 -0700
commit811cdd0282c0c415a379d882678a5c3f7ab74def (patch)
tree7c64db0c19bae775aa7bf6beef3d95b2fee57754 /redis/connection.py
parent6518c0812667b567fca365481366f07a38e0d755 (diff)
downloadredis-py-sentinel-1345.tar.gz
ConnectionPool.disconnect now accepts arg to disconnect only idle connssentinel-1345
When the sentinel's master address is changed, disconnect all idle connections in the pool.
Diffstat (limited to 'redis/connection.py')
-rwxr-xr-xredis/connection.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/redis/connection.py b/redis/connection.py
index e412f05..e3c9b66 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -1250,13 +1250,23 @@ class ConnectionPool(object):
def owns_connection(self, connection):
return connection.pid == self.pid
- def disconnect(self):
- "Disconnects all connections in the pool"
+ def disconnect(self, inuse_connections=True):
+ """
+ Disconnects connections in the pool
+
+ If ``inuse_connections`` is True, disconnect connections that are
+ current in use, potentially by other threads. Otherwise only disconnect
+ connections that are idle in the pool.
+ """
self._checkpid()
with self._lock:
- all_conns = chain(self._available_connections,
- self._in_use_connections)
- for connection in all_conns:
+ if inuse_connections:
+ connections = chain(self._available_connections,
+ self._in_use_connections)
+ else:
+ connections = self._available_connections
+
+ for connection in connections:
connection.disconnect()