nicolasff / webdis

A Redis HTTP interface with JSON output
https://webd.is
BSD 2-Clause "Simplified" License
2.84k stars 304 forks source link

Timeout when using SUBSCRIBE #132

Open behm opened 8 years ago

behm commented 8 years ago

I am calling webdis with .NET C# using the SUBSCRIBE command. I have run into situations where reading the stream gives me a timeout. Is there any way to maintain a connection? Is there a better approach than the code I have included below?

Here is the code I am using?

static async Task ReadDataFeed()
{
    var url = "http://mydomain.com:7379/SUBSCRIBE/myproduct:json:stream:5";

    using (var client = new HttpClient())
    {
        client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
        var msgBuilder = new StringBuilder();

        var request = new HttpRequestMessage(HttpMethod.Get, url);
        using (var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
        {
            using (var body = await response.Content.ReadAsStreamAsync())
            using (var reader = new StreamReader(body))
            {
                while (!reader.EndOfStream)
                {
                    // Read data from the stream
                    var buffer = new char[8192];
                    var bytesRead = await reader.ReadAsync(buffer, 0, buffer.Length);

                    //... process the buffer here
                }
            }
        }
    }
}

Thanks!