diff --git a/redisgraph/query_result.py b/redisgraph/query_result.py index 2a6e788..9eef710 100644 --- a/redisgraph/query_result.py +++ b/redisgraph/query_result.py @@ -33,6 +33,7 @@ class QueryResult(object): RELATIONSHIPS_CREATED = 'Relationships created' INDICES_CREATED = "Indices created" INDICES_DELETED = "Indices deleted" + CACHED_EXECUTION = "Cached execution" INTERNAL_EXECUTION_TIME = 'internal execution time' def __init__(self, graph, response): @@ -64,7 +65,7 @@ def parse_statistics(self, raw_statistics): stats = [self.LABELS_ADDED, self.NODES_CREATED, self.PROPERTIES_SET, self.RELATIONSHIPS_CREATED, self.NODES_DELETED, self.RELATIONSHIPS_DELETED, self.INDICES_CREATED, self.INDICES_DELETED, - self.INTERNAL_EXECUTION_TIME] + self.CACHED_EXECUTION, self.INTERNAL_EXECUTION_TIME] for s in stats: v = self._get_value(s, raw_statistics) if v is not None: @@ -227,6 +228,7 @@ def _get_value(prop, statistics): if prop in stat: return float(stat.split(': ')[1].split(' ')[0]) + return None def _get_stat(self, stat): @@ -264,6 +266,10 @@ def indices_created(self): def indices_deleted(self): return self._get_stat(self.INDICES_DELETED) + @property + def cached_execution(self): + return self._get_stat(self.CACHED_EXECUTION) == 1 + @property def run_time_ms(self): return self._get_stat(self.INTERNAL_EXECUTION_TIME) diff --git a/test.py b/test.py index 1c4f031..44b0401 100644 --- a/test.py +++ b/test.py @@ -187,5 +187,15 @@ def test_optional_match(self): redis_graph.delete() + def test_cached_execution(self): + redis_graph = Graph('cached', self.r) + redis_graph.query("CREATE ()") + uncached_result = redis_graph.query("MATCH (n) RETURN n") + cached_result = redis_graph.query("MATCH (n) RETURN n") + self.assertEqual(uncached_result.result_set, cached_result.result_set) + self.assertFalse(uncached_result.cached_execution) + self.assertTrue(cached_result.cached_execution) + redis_graph.delete() + if __name__ == '__main__': unittest.main()