Hello,
I am not sure I fully understand how parameters can be provided using JSON, but I have encountered an issue I can’t solve. Using python and the python RedisGraph module:
redisgraph
This is an exact paste from the example given:
import redis
from redisgraph import Node, Edge, Graph, Path
r = redis.Redis(host='localhost', port=6379)
redis_graph = Graph('social', r)
john = Node(label='person', properties={'name': 'John Doe', 'age': 33, 'gender': 'male', 'status': 'single'})
redis_graph.add_node(john)
japan = Node(label='country', properties={'name': 'Japan'})
redis_graph.add_node(japan)
edge = Edge(john, 'visited', japan, properties={'purpose': 'pleasure'})
redis_graph.add_edge(edge)
redis_graph.commit()
query = """MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query)
# Print resultset
result.pretty_print()
# Use parameters
params = {'purpose':"pleasure"}
query = """MATCH (p:person)-[v:visited {purpose:$purpose}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query, params)
# Print resultset
result.pretty_print()
Focus is on:
params = {'purpose':"pleasure"}
query = """MATCH (p:person)-[v:visited {purpose:$purpose}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query, params)
Works fine for me, but when I try to run this slightly modified code:
params = {'params':{'purpose':"pleasure"}}
query = """MATCH (p:person)-[v:visited {$params}]->(c:country)
RETURN p.name, p.age, v.purpose, c.name"""
result = redis_graph.query(query, params)
It trows and error:
---------------------------------------------------------------------------
ResponseError Traceback (most recent call last)
<ipython-input-44-eafe4fde3be8> in <module>
4 RETURN p.name, p.age, v.purpose, c.name"""
5
----> 6 result = redis_graph.query(query, params)
7
8 # Print resultset
~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redisgraph\graph.py in query(self, q, params)
128 result_set = None
129
--> 130 response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q, "--compact")
131 return QueryResult(self, response)
132
~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\client.py in execute_command(self, *args, **options)
899 try:
900 conn.send_command(*args)
--> 901 return self.parse_response(conn, command_name, **options)
902 except (ConnectionError, TimeoutError) as e:
903 conn.disconnect()
~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\client.py in parse_response(self, connection, command_name, **options)
913 "Parses a response from the Redis server"
914 try:
--> 915 response = connection.read_response()
916 except ResponseError:
917 if EMPTY_RESPONSE in options:
~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\redis\connection.py in read_response(self)
754
755 if isinstance(response, ResponseError):
--> 756 raise response
757 return response
758
ResponseError: errMsg: Invalid input 'a': expected PROFILE line: 1, column: 2, offset: 1 errCtx: params={'purpose': 'pleasure'} MATCH (p:person)-[v:visited {$params}]->(c:cou... errCtxOffset: 1
Is this an unsupported use case or there is a bug in the module? As far as I understand its a normal use case in Cypher. I would idealy want to use it when setting properties with the SET clause.