Skip to content

Commit fcd58ec

Browse files
gkorlandswilly22
andauthored
Add support for read_only queries (#101)
* add support for read_only queries * add test for RO_QUERY * Update test.py * Update test.py Co-authored-by: Roi Lipman <[email protected]>
1 parent fadc330 commit fcd58ec

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

redisgraph/graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def build_params_header(self, params):
141141
params_header += str(key) + "=" + str(value) + " "
142142
return params_header
143143

144-
def query(self, q, params=None, timeout=None):
144+
def query(self, q, params=None, timeout=None, read_only=False):
145145
"""
146146
Executes a query against the graph.
147147
"""
@@ -156,7 +156,7 @@ def query(self, q, params=None, timeout=None):
156156
# construct query command
157157
# ask for compact result-set format
158158
# specify known graph version
159-
command = ["GRAPH.QUERY", self.name, query, "--compact", "version", self.version]
159+
command = [("GRAPH.QUERY","GRAPH.RO_QUERY")[read_only], self.name, query, "--compact", "version", self.version]
160160

161161
# include timeout is specified
162162
if timeout:

test.py

+14
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def test_execution_plan(self):
207207

208208
redis_graph.delete()
209209

210+
210211
def test_query_timeout(self):
211212
redis_graph = Graph('timeout', self.r)
212213
# Build a sample graph with 1000 nodes.
@@ -228,6 +229,19 @@ def test_query_timeout(self):
228229
# Expecting an error.
229230
pass
230231

232+
233+
def test_read_only_query(self):
234+
redis_graph = Graph('read_only', self.r)
235+
236+
try:
237+
# Issue a write query, specifying read-only true, this call should fail.
238+
redis_graph.query("CREATE (p:person {name:'a'})", read_only=True)
239+
assert(False)
240+
except Exception as e:
241+
# Expecting an error.
242+
pass
243+
244+
231245
def test_cache_sync(self):
232246
# This test verifies that client internal graph schema cache stays
233247
# in sync with the graph schema

0 commit comments

Comments
 (0)