diff --git a/redisgraph/graph.py b/redisgraph/graph.py index 2323ede..d1b9bb2 100644 --- a/redisgraph/graph.py +++ b/redisgraph/graph.py @@ -141,7 +141,7 @@ def build_params_header(self, params): params_header += str(key) + "=" + str(value) + " " return params_header - def query(self, q, params=None, timeout=None): + def query(self, q, params=None, timeout=None, read_only=False): """ Executes a query against the graph. """ @@ -156,7 +156,7 @@ def query(self, q, params=None, timeout=None): # construct query command # ask for compact result-set format # specify known graph version - command = ["GRAPH.QUERY", self.name, query, "--compact", "version", self.version] + command = [("GRAPH.QUERY","GRAPH.RO_QUERY")[read_only], self.name, query, "--compact", "version", self.version] # include timeout is specified if timeout: diff --git a/test.py b/test.py index 74f1362..bcbbd65 100644 --- a/test.py +++ b/test.py @@ -207,6 +207,7 @@ def test_execution_plan(self): redis_graph.delete() + def test_query_timeout(self): redis_graph = Graph('timeout', self.r) # Build a sample graph with 1000 nodes. @@ -228,6 +229,19 @@ def test_query_timeout(self): # Expecting an error. pass + + def test_read_only_query(self): + redis_graph = Graph('read_only', self.r) + + try: + # Issue a write query, specifying read-only true, this call should fail. + redis_graph.query("CREATE (p:person {name:'a'})", read_only=True) + assert(False) + except Exception as e: + # Expecting an error. + pass + + def test_cache_sync(self): # This test verifies that client internal graph schema cache stays # in sync with the graph schema