Skip to content

Commit 6487f95

Browse files
authored
Add support for certain LATENCY commands (#2503)
* add latency commands * fix tests in cluster
1 parent 3a121be commit 6487f95

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

redis/cluster.py

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ class AbstractRedisCluster:
265265
"READWRITE",
266266
"TIME",
267267
"GRAPH.CONFIG",
268+
"LATENCY HISTORY",
269+
"LATENCY LATEST",
270+
"LATENCY RESET",
268271
],
269272
DEFAULT_NODE,
270273
),

redis/commands/core.py

+24
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,30 @@ def latency_histogram(self, *args):
11511151
"LATENCY HISTOGRAM is intentionally not implemented in the client."
11521152
)
11531153

1154+
def latency_history(self, event: str) -> ResponseT:
1155+
"""
1156+
Returns the raw data of the ``event``'s latency spikes time series.
1157+
1158+
For more information see https://redis.io/commands/latency-history
1159+
"""
1160+
return self.execute_command("LATENCY HISTORY", event)
1161+
1162+
def latency_latest(self) -> ResponseT:
1163+
"""
1164+
Reports the latest latency events logged.
1165+
1166+
For more information see https://redis.io/commands/latency-latest
1167+
"""
1168+
return self.execute_command("LATENCY LATEST")
1169+
1170+
def latency_reset(self, *events: str) -> ResponseT:
1171+
"""
1172+
Resets the latency spikes time series of all, or only some, events.
1173+
1174+
For more information see https://redis.io/commands/latency-reset
1175+
"""
1176+
return self.execute_command("LATENCY RESET", *events)
1177+
11541178
def ping(self, **kwargs) -> ResponseT:
11551179
"""
11561180
Ping the Redis server

tests/test_commands.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -4527,16 +4527,23 @@ def test_latency_histogram_not_implemented(self, r: redis.Redis):
45274527
with pytest.raises(NotImplementedError):
45284528
r.latency_histogram()
45294529

4530-
@skip_if_server_version_lt("7.0.0")
45314530
def test_latency_graph_not_implemented(self, r: redis.Redis):
45324531
with pytest.raises(NotImplementedError):
45334532
r.latency_graph()
45344533

4535-
@skip_if_server_version_lt("7.0.0")
45364534
def test_latency_doctor_not_implemented(self, r: redis.Redis):
45374535
with pytest.raises(NotImplementedError):
45384536
r.latency_doctor()
45394537

4538+
def test_latency_history(self, r: redis.Redis):
4539+
assert r.latency_history("command") == []
4540+
4541+
def test_latency_latest(self, r: redis.Redis):
4542+
assert r.latency_latest() == []
4543+
4544+
def test_latency_reset(self, r: redis.Redis):
4545+
assert r.latency_reset() == 0
4546+
45404547
@pytest.mark.onlynoncluster
45414548
@skip_if_server_version_lt("4.0.0")
45424549
@skip_if_redis_enterprise()

0 commit comments

Comments
 (0)