ravendb - ConsistencyOptions.QueryYourWrites 超时

标签 ravendb

我使用documentStore.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites 我的代码中的语句从 RavenDB 查询数据并且工作正常。但是如何为所有查询设置全局超时(如下面的查询所示)。

RavenQueryStatistics stats;
var results = session.Query<Product>()
.Statistics(out stats)
.Where(x => x.Price > 10)
.Customize(x => x.WaitForNonStaleResults(TimeSpan.FromSeconds(5)))
.ToArray();

最佳答案

实现Document Query Listener

public class NonStaleQueryListener(TimeSpan timeout) : IDocumentQueryListener
{
    public void BeforeQueryExecuted(IDocumentQueryCustomization customization)
    {
        customization.WaitForNonStaleResultsAsOfLastWrite(timeout);
    }
}

并像这样注册:

TimeSpan timeout = TimeSpan.FromSeconds(5);
documentStore.RegisterListener(new NonStaleQueryListener(timeout));

关于ravendb - ConsistencyOptions.QueryYourWrites 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19143506/

相关文章:

乌鸦数据库 : Difficulty with two WHERE Query

RavenDb:文档刷新功能不会在@refresh 标志指定的时间或之后运行

ravendb - Raven DB:如何删除给定类型的所有文档

c# - RavenDB 2.5 LoadByUniqueConstraint 加载失败

asp.net-mvc-3 - 另一个数据库实例 RavenDB MVC3 已使用的临时路径

RavenDB 升级

asp.net-mvc - RavenDB-如何在生产中使用多个插入?

c# - 在 RavenDB 中使用 SaveChangesAsync

c# - 在 RavenDB 中存储/检索动态数据

c# - RavenDb 从不同来源导入数据,如 xml、cvs