2

我在代码中使用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();
4

1 回答 1

2

实现文档查询侦听器

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

并像这样注册它:

TimeSpan timeout = TimeSpan.FromSeconds(5);
documentStore.RegisterListener(new NonStaleQueryListener(timeout));
于 2013-10-02T20:03:06.100 回答