I'm trying to write a producer/consumer system using Redis in C#. Each message produced must be consumed by only one consumer, and I want the consumers to wait for elements created by the consumer. My system must support many produced/consumer sets.
I am using StackExchange.Redis
to communicate with Redis, and using lists where elements are added using ListLeftPush
and removed with ListRightPop
. What I am experiencing is that while the ListRightPop
method should block until an element exists in the list (or after a defined timeout), it always returns automatically if there are no elements in the list. This is the test code I wrote to check this:
IDatabase cache = connection.GetDatabase();
Trace.TraceInformation("waiting "+DateTime.Now);
var res = cache.ListRightPop("test");
Trace.TraceInformation("Got "+res+", Ended" + DateTime.Now);
And I'm getting a nil
result after less than 1 second.
The standard pop operations do not block: they return nil if the list is empty or does not exist.
SE.Redis is a multiplexer. Using a blocking pop is a very very bad idea. This is explained more, with workarounds discussed specifically for blocking pops, in the documentation: https://stackexchange.github.io/StackExchange.Redis/PipelinesMultiplexers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With