如何从 ServiceStack.Redis 管道读取值?我在 GitHub 上看到了例子,但我不确定如果同时有许多 QueueCommand(例如,10000 个),代码能否正常工作。
QueueCommand 的回调似乎是一个异步操作。每个 QueueCommand 都可以有一个回调。当调用 Pipeline.Flush() 时,所有 QueueCommand 将以管道模式发送到 Redis 服务器,当执行其中一个 QueueCommand 时,将调用其回调。
我的问题是:当 Pipeline.Flush() 完成时,库是否保证所有回调都已执行?
这里是GitHub上的ServiceStack.Redis代码
[Test]
public void Can_call_single_operation_with_callback_3_Times_in_pipeline()
{
var results = new List<long>();
Assert.That(Redis.GetValue(Key), Is.Null);
using (var pipeline = Redis.CreatePipeline())
{
pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
pipeline.QueueCommand(r => r.IncrementValue(Key), results.Add);
//Can I assume that when Flush() finishes,
//all 3 callbacks (results.Add) would have finished?
pipeline.Flush();
}
Assert.That(Redis.GetValue(Key), Is.EqualTo("3"));
Assert.That(results, Is.EquivalentTo(new List<long> { 1, 2, 3 }));
}
最佳答案
您可以在以下位置找到 Redis Pipeline API 的一些测试:
是的,当您在 Redis 管道上调用 .Flush()
时,它是 flushes all the buffered commands to redis然后执行所有排队的回调。
关于c# - 从 ServiceStack.Redis 管道读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36882391/