4

I need to read from a REDIS stream while the server will still be writing to the STream. Now there are 2 ways. 1 way is to get a list of messages already there. I am doing it as indicated below. However i want to do a blocking read so that my client console app will wait for the messages in the stream. I know the same can be done using following command in REDIS-CLI. I want to achieve the same result in C# XREAD BLOCK 1000 STREAMS #channel1 1526999626221-0


IDatabase db = redis.GetDatabase();                
while (true)
{
    iteration++;
    //var messages = db.StreamRead("#channel1", "0-0");
    var messages = db.StreamRead("#channel1", lastMessageInAsequence);

    IEnumerator MessageEnumerator = messages.GetEnumerator();

    while (MessageEnumerator.MoveNext())
    {
        StackExchange.Redis.NameValueEntry[] entry1 = ((StackExchange.Redis.StreamEntry)MessageEnumerator.Current).Values;

        lineCount++;
        Console.WriteLine(entry1[0].Name + ":" + entry1[0].Value);
        lastMessageInAsequence = entry1[0].Name;
    }

    Console.WriteLine($"{lineCount} lines read from stream in 1 go in iteration {iteration}");
}
1

2 Answers 2

1

This is not possible currently. see https://stackexchange.github.io/StackExchange.Redis/PipelinesMultiplexers.html#multiplexing for the reasons; we have discussed some options to enable this scenario, but it needs quite a bit of work to enable it. I have no ETA on those ideas. I understand what you're trying to do, it just isn't compatible wih the library right now.

1

The package CSRedisCore can be used to complete a blocking read. See https://developer.redis.com/develop/dotnet/streams/blocking-reads/cs-redis/

We look forward to when StackExchange.Redis can do the same.

1
  • has anyone used this successfully in a production env?
    – MX313
    Nov 23, 2022 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.