Skip to content
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

Support Lua scripting and MULTI/EXEC #333

Closed
stockholmux opened this issue Jan 24, 2019 · 6 comments
Closed

Support Lua scripting and MULTI/EXEC #333

stockholmux opened this issue Jan 24, 2019 · 6 comments
Assignees
Milestone

Comments

@stockholmux
Copy link

I'd like to be able to do GRAPH.QUERY commands in a Lua script but I get Blocking module command called from Lua script issues. Additionally, I'd like to be able to run MULTI/EXEC blocks but they don't seem to be supported either.

@swilly22 swilly22 self-assigned this Feb 10, 2019
@swilly22 swilly22 added this to ToDo in RedisGraph 2.0 via automation Feb 10, 2019
@swilly22 swilly22 added this to the 1.2.0 milestone Feb 10, 2019
@swilly22
Copy link
Collaborator

#352

RedisGraph 2.0 automation moved this from ToDo to Done Feb 11, 2019
@mayureshkumbhar
Copy link

@swilly22
Tried to execute cypher commands as single transaction using WATCH/MULTI/EXEC, but could its executing as pipeline not transaction. Please find below code for reference.

Third graph CREATE command is failing as one of its param is commented, as expected its failing with redis.clients.jedis.exceptions.JedisDataException: Missing parameters still its not reverting earlier changes done by first two GRAPH CREATE.

try(RedisGraph graph = new RedisGraph();
RedisGraphContext context = graph.getContext()) {
Map<String, Object> params = new HashMap<>();
params.put("age", 30);
//Deliberately commented this line to fail the transaction
//params.put("name", "amit");
// WATCH/MULTI/EXEC
context.watch("contextSocial");
RedisGraphTransaction t = context.multi();
Response r1 = t.query("contextSocial","CREATE (:person{name:'roi',age:32})");
Response rmk = t.query("contextSocial","CREATE (:person{name:'mk',age:30})");
Response r2 = t.query("contextSocial","CREATE (:person{name:$name,age:$age})", params);
Response r3 = t.query("contextSocial", "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='mk') CREATE (a)-[:knows]->(b)");
Response r4 = t.query("contextSocial", "MATCH (a:person), (b:person) WHERE (a.name = 'amit' AND b.name='mk') CREATE (a)-[:fof]->(b)");
List execResults = t.exec();
System.out.println(execResults.toString());
//context.deleteGraph("contextSocial");
}
Output

[ResultSetImpl{header=HeaderImpl{schemaTypes=[], schemaNames=[]}, statistics=StatisticsImpl{statistics={Labels added=1, Nodes created=1, Properties set=2, Query internal execution time=0.263100 milliseconds}}, results=[]}, ResultSetImpl{header=HeaderImpl{schemaTypes=[], schemaNames=[]}, statistics=StatisticsImpl{statistics={Nodes created=1, Properties set=2, Query internal execution time=0.107500 milliseconds}}, results=[]}, redis.clients.jedis.exceptions.JedisDataException: Missing parameters, ResultSetImpl{header=HeaderImpl{schemaTypes=[], schemaNames=[]}, statistics=StatisticsImpl{statistics={Relationships created=1, Query internal execution time=0.414600 milliseconds}}, results=[]}, ResultSetImpl{header=HeaderImpl{schemaTypes=[], schemaNames=[]}, statistics=StatisticsImpl{statistics={Query internal execution time=0.277200 milliseconds}}, results=[]}]

@DvirDukhan
Copy link
Collaborator

@mayureshkumbhar
As far as I know, the Redis pipeline does not support rollbacks for failing executions within the pipeline, so the success of your first two queries will be shown in your graph. More generally speaking, RedisGraph currently does not support transactions or rollbacks for failing queries.

@mayureshkumbhar
Copy link

@DvirDukhan , Is there any way we could implement atomic execution of graph queries or transactional behaviour in Redisgraph

@DvirDukhan
Copy link
Collaborator

@mayureshkumbhar
Regarding atomic execution, I think you can use Lua scripts as they are executed on the main thread. But this will not guarantee you the rollback option.
Regarding transactional behavior, I'm sorry, but I think that every solution that I might suggest will probably be wrong since we do not support it. We just started designing transactional behavior on RedisGraph. I cannot commit on the features or ETA since it is in very early stages.

@mayureshkumbhar
Copy link

Thank you @DvirDukhan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

4 participants