I'm trying to put together a super simple queuing sample based on BookSleeve.
Here's what I have so far for the queue consumer side:
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);
}
}
}
}
I'm running the following in LINQPad as the producer:
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);
}
I'm getting some really weird results though:
1st run:
Got: foo2
Got: foo5
Got: foo7
Got: foo9
2nd run:
Got: foo1
Got: foo4
Got: foo7
3rd run:
Got: foo0
Got: foo3
Got: foo6
Got: foo8
Also, after every run, LINQPad outputs: queue length: 0
, and running LLEN test
using the actual redis client returns (integer) 0
.
I can't help but feel that I'm missing something here, most likely having to do with the async stuff, but I just can't see it.
My redis version is 2.8.3, BookSleeve version is 1.3.41.
The actual question here is: Why is BookSleeve only returning a subset of the messages that are sent to the redis list?