How does RedisGraph parse double quotation marks

When I tried to deliver a GRAPH.QUERY command to redis through hiredis, I failed. I opened the redis’ monitor, here is the message:

1617794393.314911 [0] “GRAPH.QUERY” “MotoTest” “"MATCH” “(r:Rider)-[:rides]->(t:Team)” “WHERE” “” “=” “‘Yamaha’” “RETURN” “,” “"”

As you can see. I don’t understand the inner core of RedisGraph and I sincerely ask for your help.

Hi, teams. Is this a bug?

Hi @zhu0113,

RedisGraph expects to receive the entire query as one string. Single and double quote characters are interchangeable, and quote characters within it may be backslash-escaped.

The only other thing to stay aware of is that you can’t nest quote characters of the same type within a string without escaping it, as in "Hello \" world".

The following are all equivalent and valid:

"MATCH (r:Rider)-[:rides]->(t:Team) WHERE = 'Yamaha' RETURN,"
'MATCH (r:Rider)-[:rides]->(t:Team) WHERE = "Yamaha" RETURN,'
"MATCH (r:Rider)-[:rides]->(t:Team) WHERE = \"Yamaha\" RETURN,"
1 Like

Hi, @jeffreylovitz .
Thank you for your help! You are right, ' or " doesn’t matter to RedisGraph. I just can’t make RedisGraph understand me when I use Hiredis, like this:

reply = redisCommand(graph, “GRAPH.QUERY MotoTest ‘MATCH (r:Rider)-[:rides]->(t:Team) WHERE = ‘Yamaha’ RETURN,’”);

Do you have any idea? Thanks again for your time and consideration!

So this is a good ol’ Wisdom of the Ancients scenario… hope it helps someone else:

Split it into two parts:

char *query;
asprintf(&query, "MATCH (r:Rider)-[:rides]->(t:Team) WHERE = ‘%s’ RETURN,’)", "Yamaha");
redisCommand(c, "GRAPH.QUERY MotoTest %s", query);

See Redisgraph HiRedis Syntax SO Question for more information.