diff options
author | Chayim <chayim@users.noreply.github.com> | 2022-02-16 10:26:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 10:26:31 +0200 |
commit | 0ed06603695ba9533d1086dcd7d60cd5eb5e17d0 (patch) | |
tree | 530e96469a396c221e28ac6a8b369984d01bd66c /redis/commands/graph/commands.py | |
parent | 6c00e091e93d07834fcdd811b2a8473848310db0 (diff) | |
download | redis-py-4.1.tar.gz |
Diffstat (limited to 'redis/commands/graph/commands.py')
-rw-r--r-- | redis/commands/graph/commands.py | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/redis/commands/graph/commands.py b/redis/commands/graph/commands.py index 157f628..baed1fc 100644 --- a/redis/commands/graph/commands.py +++ b/redis/commands/graph/commands.py @@ -2,6 +2,7 @@ from redis import DataError from redis.exceptions import ResponseError from .exceptions import VersionMismatchException +from .execution_plan import ExecutionPlan from .query_result import QueryResult @@ -118,27 +119,6 @@ class GraphCommands: self.nodes = {} self.edges = [] - def explain(self, query, params=None): - """ - Get the execution plan for given query, - Returns an array of operations. - For more information see `GRAPH.EXPLAIN <https://oss.redis.com/redisgraph/master/commands/#graphexplain>`_. # noqa - - Args: - - query: - The query that will be executed. - params: dict - Query parameters. - """ - if params is not None: - query = self._build_params_header(params) + query - - plan = self.execute_command("GRAPH.EXPLAIN", self.name, query) - if isinstance(plan[0], bytes): - plan = [b.decode() for b in plan] - return "\n".join(plan) - def bulk(self, **kwargs): """Internal only. Not supported.""" raise NotImplementedError( @@ -200,3 +180,33 @@ class GraphCommands: For more information see `GRAPH.LIST <https://oss.redis.com/redisgraph/master/commands/#graphlist>`_. # noqa """ return self.execute_command("GRAPH.LIST") + + def execution_plan(self, query, params=None): + """ + Get the execution plan for given query, + GRAPH.EXPLAIN returns an array of operations. + + Args: + query: the query that will be executed + params: query parameters + """ + if params is not None: + query = self._build_params_header(params) + query + + plan = self.execute_command("GRAPH.EXPLAIN", self.name, query) + return "\n".join(plan) + + def explain(self, query, params=None): + """ + Get the execution plan for given query, + GRAPH.EXPLAIN returns ExecutionPlan object. + + Args: + query: the query that will be executed + params: query parameters + """ + if params is not None: + query = self._build_params_header(params) + query + + plan = self.execute_command("GRAPH.EXPLAIN", self.name, query) + return ExecutionPlan(plan) |