Neo4j和Php处理交易中的柜台 [英] Neo4j and Php handle counter within transaction
问题描述
很好的情况是这样的:
我创建了一个称为计数节点
的节点。它的初始值为0,并随着用户在我的网站上创建帐户而增加。
I create a one node called counter node
. Its initial value is 0 and incremented as user create its account on my website.
因此,发生了三种操作:
So there are three operation happen to operate this:
读取个计数器节点
值
在php中做一些逻辑。这里像+1一样是计数器节点的先前值
写计数器节点的新值
Read counter node
value
Do some logic in php . Here like +1 to previous value of counter node
Write new value of counter node
现在的问题是,如果两个或多个用户正好来了同时创建这样的条件:
Now problem is, If two or more users are coming exactly same time and creating such a condition that
在第一个用户将新值写入计数器节点之前,第二个用户正在读取该值。因此,这将使我的计数器节点的值处于不稳定的状态。
Before first user write new value to counter node , it is being read by second user. Thus this will leave value of my 'counter node' in unstable condition.
希望您明白我的意思。
任何解决方案??
我正在使用neo4j 1.9.5和php
I am using neo4j 1.9.5 and php
Php Jadell:
Php Jadell :
https://github.com/jadell/Neo4jPHP
我听说过批处理,但不确定是否可以。
I heard of batch processing but not sure whether it will work. If any solution , Can you please give me a short example.
感谢Amit Aggarwal
Thanks Amit Aggarwal
推荐答案
使用纯REST API无法做到这一点。我会用Cypher尝试一下,也许是这样的:
You can't do that with the pure REST API. I would try it with Cypher, maybe something like:
START n=node(123)
SET n.noOfUsers = n.noOfUsers + 1
RETURN n.noOfUsers
这应该在最新版本中有效的Cypher
http://console.neo4j.org/?id=tnkldf
This should work in the latest version of Cypher http://console.neo4j.org/?id=tnkldf
这篇关于Neo4j和Php处理交易中的柜台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!