ConsistencyOptions.QueryYourWrites超时

时间:2013-10-02 17:53:29

标签: 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();

1 个答案:

答案 0 :(得分:2)

实施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));