diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 3defeceead..0b42ade606 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -1161,9 +1161,12 @@ async def get_message( return await self.handle_message(response, ignore_subscribe_messages) return None - def ping(self, message=None) -> Awaitable: + def ping(self, message=None) -> Awaitable[bool]: """ - Ping the Redis server + Ping the Redis server to test connectivity. + + Sends a PING command to the Redis server and returns True if the server + responds with "PONG". """ args = ["PING", message] if message is not None else ["PING"] return self.execute_command(*args) diff --git a/redis/client.py b/redis/client.py index cf4d77950f..df9a55092d 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1186,7 +1186,10 @@ def get_message( def ping(self, message: Union[str, None] = None) -> bool: """ - Ping the Redis server + Ping the Redis server to test connectivity. + + Sends a PING command to the Redis server and returns True if the server + responds with "PONG". """ args = ["PING", message] if message is not None else ["PING"] return self.execute_command(*args) diff --git a/redis/commands/core.py b/redis/commands/core.py index 737b09811e..ad21885b3d 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1210,11 +1210,18 @@ def latency_reset(self, *events: str) -> ResponseT: """ return self.execute_command("LATENCY RESET", *events) - def ping(self, **kwargs) -> ResponseT: + def ping(self, **kwargs) -> Union[Awaitable[bool], bool]: """ - Ping the Redis server + Ping the Redis server to test connectivity. - For more information, see https://redis.io/commands/ping + Sends a PING command to the Redis server and returns True if the server + responds with "PONG". + + This command is useful for: + - Testing whether a connection is still alive + - Verifying the server's ability to serve data + + For more information on the underlying ping command see https://redis.io/commands/ping """ return self.execute_command("PING", **kwargs)