问题
Sinking in big trouble,
Well can anyone tell me , how can i acquire write lock through cypher. Note : I will use REST APIs , So my cypher would in php.
EDITED : Scenario:
I am using Neo4j REST server and PHP to access it.
Now i have created a node say 'counter-node' which generates new user id. Logic is just add 1 to previous value.
Now If two users are coming simultaneously then first user read 'counter-node' value BUT before it can update it to 1 , second user read it . Thus value in 'counter-node' is not as expected.
Any Help
回答1:
You don't need to acquire write locks explicitly. All nodes that you modify in a transaction are write-locked automatically.
So if you do this in your logic:
start tx
increment counter node
read the value of the counter node and set it on the user node as ID
commit tx
no two users will ever get the same ID.
回答2:
The popular APOC plugin for Neo4j has a selection of explicit Locking procedures that can be called via Cypher such as call apoc.lock.nodes([nodes])
Learn more at neo4j-contrib.github.io/neo4j-apoc-procedures/#_locking
Note: as far as I can tell, this functionality doesn't exist natively in Cypher so APOC is probably your best bet.
来源:https://stackoverflow.com/questions/18480064/neo4j-php-acquire-wirte-lock