diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 326daaa8f8..95390bd66c 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -1112,9 +1112,11 @@ def __init__( self._event_dispatcher = EventDispatcher() def __repr__(self): + conn_kwargs = ",".join([f"{k}={v}" for k, v in self.connection_kwargs.items()]) return ( f"<{self.__class__.__module__}.{self.__class__.__name__}" - f"({self.connection_class(**self.connection_kwargs)!r})>" + f"(<{self.connection_class.__module__}.{self.connection_class.__name__}" + f"({conn_kwargs})>)>" ) def reset(self): diff --git a/redis/connection.py b/redis/connection.py index e87e7976a1..131ae68c61 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -1432,10 +1432,12 @@ def __init__( self.reset() - def __repr__(self) -> (str, str): + def __repr__(self) -> str: + conn_kwargs = ",".join([f"{k}={v}" for k, v in self.connection_kwargs.items()]) return ( - f"<{type(self).__module__}.{type(self).__name__}" - f"({repr(self.connection_class(**self.connection_kwargs))})>" + f"<{self.__class__.__module__}.{self.__class__.__name__}" + f"(<{self.connection_class.__module__}.{self.connection_class.__name__}" + f"({conn_kwargs})>)>" ) def get_protocol(self): diff --git a/tests/test_asyncio/test_connection_pool.py b/tests/test_asyncio/test_connection_pool.py index 09409e04a8..d016483840 100644 --- a/tests/test_asyncio/test_connection_pool.py +++ b/tests/test_asyncio/test_connection_pool.py @@ -294,13 +294,14 @@ def test_repr_contains_db_info_tcp(self): pool = redis.ConnectionPool( host="localhost", port=6379, client_name="test-client" ) - expected = "host=localhost,port=6379,db=0,client_name=test-client" + expected = "host=localhost,port=6379,client_name=test-client" assert expected in repr(pool) def test_repr_contains_db_info_unix(self): pool = redis.ConnectionPool( connection_class=redis.UnixDomainSocketConnection, path="abc", + db=0, client_name="test-client", ) expected = "path=abc,db=0,client_name=test-client" @@ -651,7 +652,7 @@ async def test_oom_error(self, r): await r.execute_command("DEBUG", "ERROR", "OOM blah blah") def test_connect_from_url_tcp(self): - connection = redis.Redis.from_url("redis://localhost") + connection = redis.Redis.from_url("redis://localhost:6379?db=0") pool = connection.connection_pool assert re.match( @@ -659,7 +660,7 @@ def test_connect_from_url_tcp(self): ).groups() == ( "ConnectionPool", "Connection", - "host=localhost,port=6379,db=0", + "db=0,host=localhost,port=6379", ) def test_connect_from_url_unix(self): @@ -671,7 +672,7 @@ def test_connect_from_url_unix(self): ).groups() == ( "ConnectionPool", "UnixDomainSocketConnection", - "path=/path/to/socket,db=0", + "path=/path/to/socket", ) @skip_if_redis_enterprise() diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 9e67659fa9..67b2fd5030 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -205,13 +205,14 @@ def test_repr_contains_db_info_tcp(self): pool = redis.ConnectionPool( host="localhost", port=6379, client_name="test-client" ) - expected = "host=localhost,port=6379,db=0,client_name=test-client" + expected = "host=localhost,port=6379,client_name=test-client" assert expected in repr(pool) def test_repr_contains_db_info_unix(self): pool = redis.ConnectionPool( connection_class=redis.UnixDomainSocketConnection, path="abc", + db=0, client_name="test-client", ) expected = "path=abc,db=0,client_name=test-client" @@ -598,7 +599,7 @@ def test_oom_error(self, r): r.execute_command("DEBUG", "ERROR", "OOM blah blah") def test_connect_from_url_tcp(self): - connection = redis.Redis.from_url("redis://localhost") + connection = redis.Redis.from_url("redis://localhost:6379?db=0") pool = connection.connection_pool assert re.match( @@ -606,7 +607,7 @@ def test_connect_from_url_tcp(self): ).groups() == ( "ConnectionPool", "Connection", - "host=localhost,port=6379,db=0", + "db=0,host=localhost,port=6379", ) def test_connect_from_url_unix(self): @@ -618,7 +619,7 @@ def test_connect_from_url_unix(self): ).groups() == ( "ConnectionPool", "UnixDomainSocketConnection", - "path=/path/to/socket,db=0", + "path=/path/to/socket", ) @skip_if_redis_enterprise()