Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python - adds config reset stat command #381

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename it to config_resetstat, to be aligned with Redis' cmd name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other config_reset_stat function

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain what are we testing here in a comment (see in Adan's)

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