我正在编写 Google App Engine Go 应用程序,但在测试某些功能时遇到问题。 Here is some sample code.问题如下:
- 我创建了一个新项目并将其保存到数据存储区
- 我在之后立即对该项目进行搜索查询(例如,获取命名空间中的所有项目)
- 元素不存在
如果我稍后查询该项目(例如,在后续页面中),则可以正常找到该项目。我知道这种行为可能是有意为部署在 GAE 上的应用程序设计的,但我希望本地数据存储能够立即用于查询。
有什么方法可以强制合并数据存储并使其适合此类查询?
最佳答案
这称为最终一致性,它是 App Engine 数据存储区的一项功能。
您可以使用 get 方法而不是查询来测试实体是否已保存。
在 Java 中,我们可以通过更改运行参数来设置本地数据存储的所需行为:
By default, the local datastore is configured to simulate the consistency model of the High Replication Datastore, with the percentage of datastore writes that are not immediately visible in global queries set to 10%.
To adjust this level of consistency, set the datastore.default_high_rep_job_policy_unapplied_job_pct system property with a value corresponding to the amount of eventual consistency you want your application to see.
我找不到与 Go 类似的东西。
关于google-app-engine - GAE Golang - 查询在保存后不立即返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24281103/