Skip to content

Commit

Permalink
remove Redis and ConnectionPool __eq__ comparison
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andymccurdy committed Feb 2, 2020
1 parent 5a1f3c4 commit 1b05075
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 80 deletions.
6 changes: 0 additions & 6 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,12 +746,6 @@ def __init__(self, host='localhost', port=6379,
def __repr__(self):
return "%s<%s>" % (type(self).__name__, repr(self.connection_pool))

def __eq__(self, other):
return (
isinstance(other, self.__class__)
and self.connection_pool == other.connection_pool
)

def set_response_callback(self, command, callback):
"Set a custom Response Callback"
self.response_callbacks[command] = callback
Expand Down
6 changes: 0 additions & 6 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,6 @@ def __repr__(self):
repr(self.connection_class(**self.connection_kwargs)),
)

def __eq__(self, other):
return (
isinstance(other, self.__class__)
and self.connection_kwargs == other.connection_kwargs
)

def reset(self):
self._lock = threading.RLock()
self._created_connections = 0
Expand Down
27 changes: 0 additions & 27 deletions tests/test_client.py

This file was deleted.

41 changes: 0 additions & 41 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,47 +88,6 @@ def test_repr_contains_db_info_unix(self):
'path=/abc,db=1,client_name=test-client>>')
assert repr(pool) == expected

def test_pool_equality(self):
connection_kwargs = {'host': 'localhost', 'port': 6379, 'db': 1}
pool1 = self.get_pool(connection_kwargs=connection_kwargs,
connection_class=redis.Connection)
pool2 = self.get_pool(connection_kwargs=connection_kwargs,
connection_class=redis.Connection)
assert pool1 == pool2

def test_pools_unequal_if_different_types(self):
connection_kwargs = {'host': 'localhost', 'port': 6379, 'db': 1}
pool = self.get_pool(connection_kwargs=connection_kwargs,
connection_class=redis.Connection)
assert pool != 0

def test_pools_unequal_if_different_hosts(self):
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
connection_kwargs2 = {'host': '127.0.0.1', 'port': 6379, 'db': 1}
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
connection_class=redis.Connection)
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
connection_class=redis.Connection)
assert pool1 != pool2

def test_pools_unequal_if_different_ports(self):
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
connection_kwargs2 = {'host': 'localhost', 'port': 6380, 'db': 1}
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
connection_class=redis.Connection)
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
connection_class=redis.Connection)
assert pool1 != pool2

def test_pools_unequal_if_different_dbs(self):
connection_kwargs1 = {'host': 'localhost', 'port': 6379, 'db': 1}
connection_kwargs2 = {'host': 'localhost', 'port': 6379, 'db': 2}
pool1 = self.get_pool(connection_kwargs=connection_kwargs1,
connection_class=redis.Connection)
pool2 = self.get_pool(connection_kwargs=connection_kwargs2,
connection_class=redis.Connection)
assert pool1 != pool2


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

0 comments on commit 1b05075

Please sign in to comment.