Skip to content

Commit 1b05075

Browse files
committed
remove Redis and ConnectionPool __eq__ comparison
After further thought this was a bad idea. Just because two connection pools share the same connection arguments does not make them equal. It would seem quite odd if pool_a == pool_b yet pool_a.disconnect() doesn't close all of pool_b's connections. Ref #1240 Fixes #1277 Fixes #1275 Fixes #1267 Fixes #1273
1 parent 5a1f3c4 commit 1b05075

File tree

4 files changed

+0
-80
lines changed

4 files changed

+0
-80
lines changed

redis/client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,6 @@ def __init__(self, host='localhost', port=6379,
746746
def __repr__(self):
747747
return "%s<%s>" % (type(self).__name__, repr(self.connection_pool))
748748

749-
def __eq__(self, other):
750-
return (
751-
isinstance(other, self.__class__)
752-
and self.connection_pool == other.connection_pool
753-
)
754-
755749
def set_response_callback(self, command, callback):
756750
"Set a custom Response Callback"
757751
self.response_callbacks[command] = callback

redis/connection.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,12 +1100,6 @@ def __repr__(self):
11001100
repr(self.connection_class(**self.connection_kwargs)),
11011101
)
11021102

1103-
def __eq__(self, other):
1104-
return (
1105-
isinstance(other, self.__class__)
1106-
and self.connection_kwargs == other.connection_kwargs
1107-
)
1108-
11091103
def reset(self):
11101104
self._lock = threading.RLock()
11111105
self._created_connections = 0

tests/test_client.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/test_connection_pool.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -88,47 +88,6 @@ def test_repr_contains_db_info_unix(self):
8888
'path=/abc,db=1,client_name=test-client>>')
8989
assert repr(pool) == expected
9090

91-
def test_pool_equality(self):
92-
connection_kwargs = {'host': 'localhost', 'port': 6379, 'db': 1}
93-
pool1 = self.get_pool(connection_kwargs=connection_kwargs,
94-
connection_class=redis.Connection)
95-
pool2 = self.get_pool(connection_kwargs=connection_kwargs,
96-
connection_class=redis.Connection)
97-
assert pool1 == pool2
98-
99-
def test_pools_unequal_if_different_types(self):
100-
connection_kwargs = {'host': 'localhost', 'port': 6379, 'db': 1}
101-
pool = self.get_pool(connection_kwargs=connection_kwargs,
102-
connection_class=redis.Connection)
103-
assert pool != 0
104-
105-
def test_pools_unequal_if_different_hosts(self):
106-
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
107-
connection_kwargs2 = {'host': '127.0.0.1', 'port': 6379, 'db': 1}
108-
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
109-
connection_class=redis.Connection)
110-
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
111-
connection_class=redis.Connection)
112-
assert pool1 != pool2
113-
114-
def test_pools_unequal_if_different_ports(self):
115-
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
116-
connection_kwargs2 = {'host': 'localhost', 'port': 6380, 'db': 1}
117-
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
118-
connection_class=redis.Connection)
119-
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
120-
connection_class=redis.Connection)
121-
assert pool1 != pool2
122-
123-
def test_pools_unequal_if_different_dbs(self):
124-
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
125-
connection_kwargs2 = {'host': 'localhost', 'port': 6379, 'db': 2}
126-
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
127-
connection_class=redis.Connection)
128-
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
129-
connection_class=redis.Connection)
130-
assert pool1 != pool2
131-
13291

13392
class TestBlockingConnectionPool(object):
13493
def get_pool(self, connection_kwargs=None, max_connections=10, timeout=20):

0 commit comments

Comments
 (0)