title: Recovering from Redis connectivity loss
body: <p>I am looking for the reference implementation of the recovery [in multi-threaded environment] after Redis connection has been lost. Was not able to find anything that makes sense so far.</p>
  
  <p>Setup: I have an Azure worker role that runs the same code (ThreadProc) in multiple threads. Initially, I had static ConnectionMultiplexer and did .GetDatabase() before every Redis operation. That didn't pass stress testing at all (tons of "can't connect" errors once the load increased from low to moderate). I have changed it to this:</p>
  
  <pre><code>static readonly ConnectionMultiplexer _connection = ConnectionMultiplexer.Connect(...);
  static readonly IDatabase _cache = _connection.GetDatabase();
  
  void ThreadProc() // running in multiple threads
  {
      while (true)
      {
        // using _cache here
      }
  }
  </code></pre>
  
  <p>That worked pretty well even under high load (1000+ op/s per worker role instance) until I got "No connection is available to service this operation", and the thing can't recover since.</p>
  
  <p>Please let me know what would be the correct/recommended code that can recover from intermittent connectivity problems.</p>