Neo4j PHP Acquire wirte lock

我怕爱的太早我们不能终老 提交于 2019-12-13 05:15:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!