py2neo缓存烧死了我吗? [英] Is py2neo caching burning me?
问题描述
我正在运行以下代码:
c = """
match(r:XX)
optional match(r)-[]-(m) with count(m) as mc, r match(x)
return count(x) as all, r, mc
"""
(snip!)
while(True):
tx = remote_graph.cypher.begin()
res = remote_graph.cypher.execute(c)
tx.rollback()
time.sleep(15)
(snip!)
事实上,XX节点的属性每秒都在变化-守护进程正在运行.但是,当我运行此命令时,总是在res
中获得相同的值,但仅对于r
-all
正在更改.查询没有改变.我想知道py2neo是否注意到了这一点并且没有执行查询,但是返回的是缓存副本吗?如果是这样,我该如何阻止这种情况发生?
I know for a fact the XX node's properties are changing every second - there a daemon running. However, when I run this, I always get the same values back in res
but for r
only - all
is changing. The query isn't changing. I wonder if py2neo is noticing this and not executing the query, but is returning me a cached copy? If so, how do I stop this from happening?
编辑-更多信息-我从ipython中运行了以上内容.
EDIT - more info - I ran the above from within ipython.
推荐答案
有趣的是,当您返回节点时,py2neo会记住"该节点:
Interesting enough, py2neo 'remembers' the node when you return the node:
MATCH (n:Node) RETURN n
但是当您返回单个属性时,它们将始终被更新:
But when you return individual properties, they will always be updated:
MATCH (n:Node) RETURN n.value
对于您的查询,这意味着在while
循环中两次返回同一节点时必须运行my_node.pull()
:
For your query that means you have to run my_node.pull()
when you return the same node twice in a while
loop:
while True:
q = "MATCH (n:Node) RETURN n"
result = graph.cypher.execute(q)
my_node = result[0][0]
my_node.pull()
print(my_node)
您还可以将pull()
以外的所有内容移出循环:
You can also move everything besides the pull()
out of the loop:
q = "MATCH (n:Node) RETURN n"
result = graph.cypher.execute(q)
my_node = result[0][0]
while True:
my_node.pull()
print(my_node)
这是描述行为的最小示例: http://paste.ubuntu.com/14015568/
Here is a minimal example describing the behaviour: http://paste.ubuntu.com/14015568/
我不太确定为什么py2neo在运行新查询时为什么不返回更新的节点数据.
I'm not really sure why py2neo does not return updated node data when you run a new query.
这篇关于py2neo缓存烧死了我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!