Neo4j and Php handle counter within transaction

本秂侑毒 提交于 2019-12-06 16:45:25

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

This should work in the latest version of Cypher http://console.neo4j.org/?id=tnkldf

Neo4j 2.0 has mandatory transactions. If you incremented your counter property noOfUsers in a transaction, I'd think that would help you with your concurrency issue.

Just a thought, but first a question: What's the purpose of the counter? Is it for assigning user IDs, or is it strictly informational? If the latter, must you have an exact count? Eg if you wanted the total number of twitter or facebook users, would it matter if the count was off by a few? If the count doesn't need to be exact (or exact at a particular instance in time), you could run a periodic process to return the count of user nodes, like:

MATCH n:User
return count(*)

This would also help you deal with deleted nodes.

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