Skip to content

Add support for read_only queries #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down