Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# BookSleeve BlockingRemoveLeft仅返回推送到列表中的部分项目_C#_Redis_Booksleeve - Fatal编程技术网

C# BookSleeve BlockingRemoveLeft仅返回推送到列表中的部分项目

C# BookSleeve BlockingRemoveLeft仅返回推送到列表中的部分项目,c#,redis,booksleeve,C#,Redis,Booksleeve,我正在尝试根据BookSleeve收集一个超级简单的排队示例 到目前为止,我为队列消费者端提供了以下信息: using System; using System.Text; using BookSleeve; static class Program { static void Main() { using (var redis = new RedisConnection("127.0.0.1")) { redis.Ope

我正在尝试根据BookSleeve收集一个超级简单的排队示例

到目前为止,我为队列消费者端提供了以下信息:

using System;
using System.Text;
using BookSleeve;

static class Program
{
    static void Main()
    {
        using (var redis = new RedisConnection("127.0.0.1"))
        {
            redis.Open();
            while (true)
            {
                // BRPOP the queue
                var t = redis.Lists.BlockingRemoveFirst(0, new[] { "test" }, 0);
                t.Wait();
                var val = Encoding.UTF8.GetString(t.Result.Item2);
                Console.WriteLine("Got: {0}", val);
            }
        }
    }
}
作为制片人,我正在运行以下内容:

using(var redis = new RedisConnection("localhost")) 
{
    redis.Open();
    foreach(var i in Enumerable.Range(0, 10)) 
    {
        // LPUSH
        redis.Lists.AddFirst(0, "test", "foo" + i)
            // Call wait to keep things in order
            .Wait();
    }   

    Thread.Sleep(500); // Let Redis do it's thing
    Console.WriteLine("queue length: " + redis.Lists.GetLength(0, "test").Result);
}
但我得到了一些非常奇怪的结果:

第一次运行:

Got: foo2
Got: foo5
Got: foo7
Got: foo9
第二轮:

Got: foo1
Got: foo4
Got: foo7
第三次运行:

Got: foo0
Got: foo3
Got: foo6
Got: foo8
此外,每次运行后,LINQPad都会输出:
队列长度:0
,并且使用实际的redis客户端运行
LLEN test
,返回
(整数)0

我忍不住觉得我在这里遗漏了一些东西,很可能是异步的东西,但我就是看不到

我的redis版本是2.8.3,书架版本是1.3.41


这里的实际问题是:为什么BookSleeve只返回发送到redis列表的消息的子集?

我无法让它出错。你是否绝对肯定你只有一个消费者?请注意,顺序不可预测的原因是,您将其用作堆栈而不是队列-要获得可靠的顺序,您应该从开始添加到结尾并从结尾删除,或者从结尾添加到结尾并从开始删除。如果从一开始就添加和删除,则是随机顺序

然而,它对我来说很好。控制台输出:

Got: foo0
Got: foo1
Got: foo3
Got: foo5
Got: foo6
Got: foo8
Got: foo9
Got: foo7
Got: foo4
Got: foo2
queue length: 0
我建议在
monitor
模式下使用
redis cli
——对我来说,我得到以下输出:

redis 127.0.0.1:6379> monitor
OK
1389454168.068869 [0 127.0.0.1:4957] "INFO"
1389454168.068869 [0 127.0.0.1:4957] "CONFIG" "GET" "timeout"
1389454168.068869 [0 127.0.0.1:4957] "DEL" "test"
1389454168.129869 [0 127.0.0.1:4958] "INFO"
1389454168.129869 [0 127.0.0.1:4958] "CONFIG" "GET" "timeout"
1389454168.136869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.139872 [0 127.0.0.1:4959] "INFO"
1389454168.139872 [0 127.0.0.1:4959] "CONFIG" "GET" "timeout"
1389454168.139872 [0 127.0.0.1:4959] "LPUSH" "test" "foo0"
1389454168.142869 [0 127.0.0.1:4959] "LPUSH" "test" "foo1"
1389454168.142869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.142869 [0 127.0.0.1:4959] "LPUSH" "test" "foo2"
1389454168.143871 [0 127.0.0.1:4959] "LPUSH" "test" "foo3"
1389454168.143871 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.143871 [0 127.0.0.1:4959] "LPUSH" "test" "foo4"
1389454168.143871 [0 127.0.0.1:4959] "LPUSH" "test" "foo5"
1389454168.144870 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.144870 [0 127.0.0.1:4959] "LPUSH" "test" "foo6"
1389454168.144870 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.144870 [0 127.0.0.1:4959] "LPUSH" "test" "foo7"
1389454168.145869 [0 127.0.0.1:4959] "LPUSH" "test" "foo8"
1389454168.145869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.145869 [0 127.0.0.1:4959] "LPUSH" "test" "foo9"
1389454168.145869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.146869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.146869 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.147870 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.147870 [0 127.0.0.1:4958] "BLPOP" "test" "0"
1389454168.648594 [0 127.0.0.1:4959] "LLEN" "test"
这里,连接4957只是移除密钥(以确保已知状态);4958是消费者,4959是生产者

作为参考,我在上面的测试中使用了(因为我在我的Windows笔记本电脑上,没有时间设置linux虚拟机),但是:我也希望在正式的linux版本上使用相同的

因此,请再说一遍:您确定(通过redis cli)这里只涉及2个连接吗

如果我更改为
AddLast

Got: foo0
Got: foo1
Got: foo2
Got: foo3
Got: foo4
Got: foo5
Got: foo6
Got: foo7
Got: foo8
Got: foo9
queue length: 0

我今晚去看看。作为旁注:我通常会说“避免阻塞呼叫(更喜欢发布/订阅通知)”——这会让多路复用器受到疯狂的伤害。然而,它应该起作用。稍后会有更多。随机的想法:你不可能在某处运行消费者exe的第二个副本来携带一些物品吗?事实上,这是我检查的第一件事。这是当时连接到redis的唯一一个进程。k-目前正忙于处理家庭事务,但稍后将查看其他想法:您还可以使用
客户机列表
查看当前连接及其最后命令、当前状态等。特别是,
flags
属性包含一个
b
,如果它是一个阻塞操作。我来试一试。让我感到困惑的是,在重新启动redis(我在Linux虚拟机上运行redis)后,我立即出现了这种行为?我认为我发布的代码应该产生FIFObehavior@ross我在回答中解释了这一点,并(见结尾)展示了如何修复它。基本上,不,你没有写FIFOI知道发生了什么事(它确实与孤立的连接有关),要写一篇关于它的博客文章。