title: Maintaining an open Redis PubSub subscription with Booksleeve
body: <p>I am using a Redis pubsub channel to send messages from a pool of worker processes to my ASP.NET application. When a message is received, my application forwards the message to a client's browser with SignalR.</p>
  
  <p>I found <a href="https://stackoverflow.com/a/8777999/145831">this solution</a> to maintaining an open connection to Redis, but it doesn't account for subscriptions when it recreates the connection.</p>
  
  <p>I'm currently handling Redis pubsub messages in my Global.asax file:</p>
  
  <pre><code>public class Application : HttpApplication
  {
      protected void Application_Start()
      {
          var gateway = Resolve&lt;RedisConnectionGateway&gt;();
          var connection = gateway.GetConnection();
          var channel = connection.GetOpenSubscriberChannel();
  
          channel.PatternSubscribe("workers:job-done:*", OnExecutionCompleted);
      }
  
      /// &lt;summary&gt;
      /// Handle messages received from workers through Redis.&lt;/summary&gt;
      private static void OnExecutionCompleted(string key, byte[] message)
      {
          /* forwarded the response to the client that requested it */
      }
  }
  </code></pre>
  
  <p>The problem occurs when the current RedisConnection is closed for whatever reason. The simplest solution the problem would be to fire an event from the <code>RedisConnectionGateway</code> class when the connection has been reset, and resubscribe using a new <code>RedisSubscriberChannel</code>. However, any messages published to the channel while the connection is being reset would be lost.</p>
  
  <p>Are there any examples of recommended ways to handle this situation?</p>