diff options
author | dvora-h <67596500+dvora-h@users.noreply.github.com> | 2022-12-14 11:17:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-14 11:17:51 +0200 |
commit | 6487f9555ba2d08083a081df9b65b642427361fa (patch) | |
tree | 26e741fb2fdd7200c20f34185ec6f09d633e0f4c | |
parent | 3a121bef7bbc5bb5f07b119b0eef2f7527a38eda (diff) | |
download | redis-py-6487f9555ba2d08083a081df9b65b642427361fa.tar.gz |
Add support for certain LATENCY commands (#2503)
* add latency commands
* fix tests in cluster
-rw-r--r-- | redis/cluster.py | 3 | ||||
-rw-r--r-- | redis/commands/core.py | 24 | ||||
-rw-r--r-- | tests/test_commands.py | 11 |
3 files changed, 36 insertions, 2 deletions
diff --git a/redis/cluster.py b/redis/cluster.py index 0b2c4f1..cd559b6 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -265,6 +265,9 @@ class AbstractRedisCluster: "READWRITE", "TIME", "GRAPH.CONFIG", + "LATENCY HISTORY", + "LATENCY LATEST", + "LATENCY RESET", ], DEFAULT_NODE, ), diff --git a/redis/commands/core.py b/redis/commands/core.py index 2ebd35f..eaedffb 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -1151,6 +1151,30 @@ class ManagementCommands(CommandsProtocol): "LATENCY HISTOGRAM is intentionally not implemented in the client." ) + def latency_history(self, event: str) -> ResponseT: + """ + Returns the raw data of the ``event``'s latency spikes time series. + + For more information see https://redis.io/commands/latency-history + """ + return self.execute_command("LATENCY HISTORY", event) + + def latency_latest(self) -> ResponseT: + """ + Reports the latest latency events logged. + + For more information see https://redis.io/commands/latency-latest + """ + return self.execute_command("LATENCY LATEST") + + def latency_reset(self, *events: str) -> ResponseT: + """ + Resets the latency spikes time series of all, or only some, events. + + For more information see https://redis.io/commands/latency-reset + """ + return self.execute_command("LATENCY RESET", *events) + def ping(self, **kwargs) -> ResponseT: """ Ping the Redis server diff --git a/tests/test_commands.py b/tests/test_commands.py index 77e2e72..12ffcfe 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -4527,16 +4527,23 @@ class TestRedisCommands: with pytest.raises(NotImplementedError): r.latency_histogram() - @skip_if_server_version_lt("7.0.0") def test_latency_graph_not_implemented(self, r: redis.Redis): with pytest.raises(NotImplementedError): r.latency_graph() - @skip_if_server_version_lt("7.0.0") def test_latency_doctor_not_implemented(self, r: redis.Redis): with pytest.raises(NotImplementedError): r.latency_doctor() + def test_latency_history(self, r: redis.Redis): + assert r.latency_history("command") == [] + + def test_latency_latest(self, r: redis.Redis): + assert r.latency_latest() == [] + + def test_latency_reset(self, r: redis.Redis): + assert r.latency_reset() == 0 + @pytest.mark.onlynoncluster @skip_if_server_version_lt("4.0.0") @skip_if_redis_enterprise() |