diff --git a/redis/commands/graph/query_result.py b/redis/commands/graph/query_result.py index 644ac5a3db..3ffa664791 100644 --- a/redis/commands/graph/query_result.py +++ b/redis/commands/graph/query_result.py @@ -9,10 +9,12 @@ from .path import Path LABELS_ADDED = "Labels added" +LABELS_REMOVED = "Labels removed" NODES_CREATED = "Nodes created" NODES_DELETED = "Nodes deleted" RELATIONSHIPS_DELETED = "Relationships deleted" PROPERTIES_SET = "Properties set" +PROPERTIES_REMOVED = "Properties removed" RELATIONSHIPS_CREATED = "Relationships created" INDICES_CREATED = "Indices created" INDICES_DELETED = "Indices deleted" @@ -21,8 +23,10 @@ STATS = [ LABELS_ADDED, + LABELS_REMOVED, NODES_CREATED, PROPERTIES_SET, + PROPERTIES_REMOVED, RELATIONSHIPS_CREATED, NODES_DELETED, RELATIONSHIPS_DELETED, @@ -323,40 +327,60 @@ def _get_stat(self, stat): @property def labels_added(self): + """Returns the number of labels added in the query""" return self._get_stat(LABELS_ADDED) + @property + def labels_removed(self): + """Returns the number of labels removed in the query""" + return self._get_stat(LABELS_REMOVED) + @property def nodes_created(self): + """Returns the number of nodes created in the query""" return self._get_stat(NODES_CREATED) @property def nodes_deleted(self): + """Returns the number of nodes deleted in the query""" return self._get_stat(NODES_DELETED) @property def properties_set(self): + """Returns the number of properties set in the query""" return self._get_stat(PROPERTIES_SET) + @property + def properties_removed(self): + """Returns the number of properties removed in the query""" + return self._get_stat(PROPERTIES_REMOVED) + @property def relationships_created(self): + """Returns the number of relationships created in the query""" return self._get_stat(RELATIONSHIPS_CREATED) @property def relationships_deleted(self): + """Returns the number of relationships deleted in the query""" return self._get_stat(RELATIONSHIPS_DELETED) @property def indices_created(self): + """Returns the number of indices created in the query""" return self._get_stat(INDICES_CREATED) @property def indices_deleted(self): + """Returns the number of indices deleted in the query""" return self._get_stat(INDICES_DELETED) @property def cached_execution(self): + """Returns whether or not the query execution plan was cached""" return self._get_stat(CACHED_EXECUTION) == 1 @property def run_time_ms(self): + """Returns the server execution time of the query""" return self._get_stat(INTERNAL_EXECUTION_TIME) diff --git a/tests/test_graph.py b/tests/test_graph.py index 76f8794c18..526308c672 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -1,7 +1,24 @@ +from unittest.mock import patch + import pytest from redis.commands.graph import Edge, Node, Path from redis.commands.graph.execution_plan import Operation +from redis.commands.graph.query_result import ( + CACHED_EXECUTION, + INDICES_CREATED, + INDICES_DELETED, + INTERNAL_EXECUTION_TIME, + LABELS_ADDED, + LABELS_REMOVED, + NODES_CREATED, + NODES_DELETED, + PROPERTIES_REMOVED, + PROPERTIES_SET, + RELATIONSHIPS_CREATED, + RELATIONSHIPS_DELETED, + QueryResult, +) from redis.exceptions import ResponseError from tests.conftest import skip_if_redis_enterprise @@ -575,3 +592,33 @@ def test_explain(client): assert result.structured_plan == expected redis_graph.delete() + + +@pytest.mark.redismod +def test_resultset_statistics(client): + with patch.object(target=QueryResult, attribute="_get_stat") as mock_get_stats: + result = client.graph().query("RETURN 1") + result.labels_added + mock_get_stats.assert_called_with(LABELS_ADDED) + result.labels_removed + mock_get_stats.assert_called_with(LABELS_REMOVED) + result.nodes_created + mock_get_stats.assert_called_with(NODES_CREATED) + result.nodes_deleted + mock_get_stats.assert_called_with(NODES_DELETED) + result.properties_set + mock_get_stats.assert_called_with(PROPERTIES_SET) + result.properties_removed + mock_get_stats.assert_called_with(PROPERTIES_REMOVED) + result.relationships_created + mock_get_stats.assert_called_with(RELATIONSHIPS_CREATED) + result.relationships_deleted + mock_get_stats.assert_called_with(RELATIONSHIPS_DELETED) + result.indices_created + mock_get_stats.assert_called_with(INDICES_CREATED) + result.indices_deleted + mock_get_stats.assert_called_with(INDICES_DELETED) + result.cached_execution + mock_get_stats.assert_called_with(CACHED_EXECUTION) + result.run_time_ms + mock_get_stats.assert_called_with(INTERNAL_EXECUTION_TIME)