Skip to content

Commit

Permalink
Python - adds config reset stat command (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Aug 30, 2023
1 parent 72bbd02 commit 8051a15
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
10 changes: 9 additions & 1 deletion python/python/pybushka/async_commands/cmd_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def custom_command(self, command_args: List[str]) -> TResult:
connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])
Args:
command_args (List[str]): List of strings of the command's arguements.
command_args (List[str]): List of strings of the command's arguments.
Every part of the command, including the command name and subcommands, should be added as a separate value in args.
Returns:
Expand Down Expand Up @@ -86,3 +86,11 @@ async def select(self, index: int) -> OK:
A simple OK response.
"""
return await self._execute_command(RequestType.Select, [str(index)])

async def config_reset_stat(self) -> OK:
"""Reset the statistics reported by Redis.
See https://redis.io/commands/config-resetstat/ for details.
Returns:
OK: Returns "OK" to confirm that the statistics were successfully reset.
"""
return await self._execute_command(RequestType.ConfigResetStat, [])
24 changes: 19 additions & 5 deletions python/python/pybushka/async_commands/cme_commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, Union

from pybushka.async_commands.core import BaseTransaction, CoreCommands, InfoSection
from pybushka.constants import TResult
from pybushka.constants import OK, TResult
from pybushka.protobuf.redis_request_pb2 import RequestType
from pybushka.routes import TRoute

Expand All @@ -24,9 +24,9 @@ async def custom_command(
connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"], AllNodes())
Args:
command_args (List[str]): List of strings of the command's arguements.
command_args (List[str]): List of strings of the command's arguments.
Every part of the command, including the command name and subcommands, should be added as a separate value in args.
route (Optional[TRoute], optional): The command will be routed automatically, unless `route` is provided, in which
route (Optional[TRoute]): The command will be routed automatically, unless `route` is provided, in which
case the client will initially try to route the command to the nodes defined by `route`. Defaults to None.
Returns:
Expand All @@ -47,7 +47,7 @@ async def info(
Args:
sections (Optional[List[InfoSection]]): A list of InfoSection values specifying which sections of
information to retrieve. When no parameter is provided, the default option is assumed.
route (Optional[TRoute], optional): The command will be routed automatically, unless `route` is provided, in which
route (Optional[TRoute]): The command will be routed automatically, unless `route` is provided, in which
case the client will initially try to route the command to the nodes defined by `route`. Defaults to None.
Returns:
Expand All @@ -68,7 +68,7 @@ async def exec(
Args:
transaction (ClusterTransaction): A ClusterTransaction object containing a list of commands to be executed.
route (Optional[TRoute], optional): The command will be routed automatically, unless `route` is provided, in which
route (Optional[TRoute]): The command will be routed automatically, unless `route` is provided, in which
case the client will initially try to route the command to the nodes defined by `route`. Defaults to None.
Returns:
Expand All @@ -78,3 +78,17 @@ async def exec(
"""
commands = transaction.commands[:]
return await self.execute_transaction(commands, route)

async def config_reset_stat(
self,
route: Optional[TRoute] = None,
) -> OK:
"""Reset the statistics reported by Redis.
See https://redis.io/commands/config-resetstat/ for details.
Args:
route (Optional[TRoute]): The command will be routed automatically, unless `route` is provided, in which
case the client will initially try to route the command to the nodes defined by `route`. Defaults to None.
Returns:
OK: Returns "OK" to confirm that the statistics were successfully reset.
"""
return await self._execute_command(RequestType.ConfigResetStat, [], route)
10 changes: 9 additions & 1 deletion python/python/pybushka/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def custom_command(self, command_args: List[str]):
connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])
Args:
command_args (List[str]): List of strings of the command's arguements.
command_args (List[str]): List of strings of the command's arguments.
Every part of the command, including the command name and subcommands, should be added as a separate value in args.
Command response:
Expand Down Expand Up @@ -228,6 +228,14 @@ def delete(self, keys: List[str]):
"""
self.append_command(RequestType.Del, keys)

def config_reset_stat(self):
"""Reset the statistics reported by Redis.
See https://redis.io/commands/config-resetstat/ for details.
Command response:
OK: Returns "OK" to confirm that the statistics were successfully reset.
"""
self.append_command(RequestType.ConfigResetStat, [])


class CoreCommands:
async def set(
Expand Down
15 changes: 15 additions & 0 deletions python/python/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ async def test_delete(self, redis_client: BaseRedisClient):
assert await redis_client.delete(delete_keys) == 3
assert await redis_client.delete(keys) == 0

@pytest.mark.parametrize("cluster_mode", [True, False])
async def test_config_reset_stat(self, redis_client: BaseRedisClient):
await redis_client.set("foo", "bar")
info_stats = parse_info_response(
get_first_result(await redis_client.info([InfoSection.STATS]))
)
assert int(info_stats["total_commands_processed"]) > 1
assert await redis_client.config_reset_stat() == OK
info_stats = parse_info_response(
get_first_result(await redis_client.info([InfoSection.STATS]))
)

# 1 stands for the second info command
assert info_stats["total_commands_processed"] == "1"


class CommandsUnitTests:
def test_expiry_cmd_args(self):
Expand Down

0 comments on commit 8051a15

Please sign in to comment.