c# - 从 ServiceStack.Redis 管道读取值

标签 c# redis servicestack.redis

如何从 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/

相关文章:

c# - 通过单击按钮将焦点设置到另一个控件

java - 空指针异常 : Cannot send from MessageListener to client via websocket with Spring boot

c# - 如何使用 ServiceStack Redis API?

python - redis - 每 20 分钟从套接字读取超时

Redis 扫描计数 : How to force SCAN to return all keys matching a pattern?

c# - ServiceStack:如何使用分布式RedisEvents?

使用 ServiceStack 在分布式环境中订阅 Redis 键空间通知

c# - 如何从动态生成的程序集中引用 GAC 程序集?

c# - 错误 : No exports were found that match the constraint:

c# - 一个类轮在列表中获得最大的东西