Skip to content

Commit

Permalink
Python adds PING command
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored and acarbonetto committed Sep 26, 2023
1 parent f6cf385 commit d3ed3b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/python/pybushka/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@ def decrby(self, key: str, amount: int):
"""
self.append_command(RequestType.DecrBy, [key, str(amount)])

def ping(self, message: Optional[str] = None):
"""Ping the Redis server.
See https://redis.io/commands/ping/ for more details.
Args:
message (Optional[str]): An optional message to include in the PING command. If not provided,
the server will respond with "PONG". If provided, the server will respond with a copy of the message.
Command response:
str: "PONG" if 'message' is not provided, otherwise return a copy of 'message'.
"""
argument = [] if message is None else [message]
self.append_command(RequestType.Ping, argument)


class CoreCommands(Protocol):
async def _execute_command(
Expand Down
5 changes: 5 additions & 0 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ async def test_mset_mget(self, redis_client: TRedisClient):
keys[-1] = None
assert mget_res == keys

@pytest.mark.parametrize("cluster_mode", [True, False])
async def test_ping(self, redis_client: TRedisClient):
assert await redis_client.ping() == "PONG"
assert await redis_client.ping("HELLO") == "HELLO"


class TestCommandsUnitTests:
def test_expiry_cmd_args(self):
Expand Down

0 comments on commit d3ed3b5

Please sign in to comment.