title: StackExchange.Redis timeout
body: <p>Production environment is on Azure, using <code>Redis Cache Standard 2.5GB</code>.</p>
  
  <p><strong>Example 1</strong></p>
  
  <blockquote>
    <p>System.Web.HttpUnhandledException (0x80004005): Exception of type
    'System.Web.HttpUnhandledException' was thrown. --->
    StackExchange.Redis.RedisTimeoutException: Timeout performing SETNX
    User.313123, inst: 49, mgr: Inactive, err: never, queue: 0, qu: 0, qs:
    0, qc: 0, wr: 0, wq: 0, in: 0, ar: 0, clientName: PRD-VM-WEB-2,
    serverEndpoint: Unspecified/Construct3.redis.cache.windows.net:6380,
    keyHashSlot: 15649, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER:
    (Busy=1,Free=32766,Min=1,Max=32767) (Please take a look at this
    article for some common client-side issues that can cause timeouts:
    <a href="http://stackexchange.github.io/StackExchange.Redis/Timeouts" rel="noreferrer">http://stackexchange.github.io/StackExchange.Redis/Timeouts</a>) at
    StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message
    message, ResultProcessor<code>1 processor, ServerEndPoint server) in
    c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line
    2120 at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message,
    ResultProcessor</code>1 processor, ServerEndPoint server) in
    c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line
    81</p>
  </blockquote>
  
  <p><strong>Example 2</strong></p>
  
  <blockquote>
    <p>StackExchange.Redis.RedisTimeoutException: Timeout performing GET
    ForumTopic.33831, inst: 1, mgr: Inactive, err: never, queue: 2, qu: 0,
    qs: 2, qc: 0, wr: 0, wq: 0, in: 0, ar: 0, clientName: PRD-VM-WEB-2,
    serverEndpoint: Unspecified/Construct3.redis.cache.windows.net:6380,
    keyHashSlot: 5851, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER:
    (Busy=1,Free=32766,Min=1,Max=32767) (Please take a look at this
    article for some common client-side issues that can cause timeouts:
    <a href="http://stackexchange.github.io/StackExchange.Redis/Timeouts" rel="noreferrer">http://stackexchange.github.io/StackExchange.Redis/Timeouts</a>)    at
    StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message
    message, ResultProcessor<code>1 processor, ServerEndPoint server) in
    c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line
    2120    at StackExchange.Redis.RedisBase.ExecuteSync[T](Message
    message, ResultProcessor</code>1 processor, ServerEndPoint server) in
    c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line
    81    at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key,
    CommandFlags flags) in
    c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line
    1647    at
    C3.Code.Controls.Application.Caching.Distributed.DistributedCacheController.Get[T](String
    cacheKey) in
    C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Distributed\DistributedCacheController.cs:line
    115    at
    C3.Code.Controls.Application.Caching.Manager.Manager.Get[T](String
    key, Func`1 getFromExternFunction, Boolean skipLocalCaches) in
    C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Manager\Manager.cs:line
    159    at C3.PageControls.Forums.TopicRender.Page_Load(Object sender,
    EventArgs e) in
    C:\Construct.net\Source\C3Alpha2\PageControls\Forums\TopicRender.ascx.cs:line
    40    at System.Web.UI.Control.OnLoad(EventArgs e)    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Control.LoadRecursive()    at
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p>
  </blockquote>
  
  <p>These errors are sporadic, several times a day.</p>
  
  <p>Is this an Azure network blip, or something I can reduce?  Looking at the numbers in the error doesn't seem anything out of the ordinary, and the server load never seems to go above 7% as reported by Azure.</p>
  
  <p><strong>Redis connection</strong></p>
  
  <pre><code>internal static class RedisController
  {
      private static readonly object GetConnectionLock = new object();
      public static ConnectionMultiplexer GetConnection()
      {
          if (Global.RedisConnection == null)
          {
              lock (GetConnectionLock)
              {
                  if (Global.RedisConnection == null)
                  {
                      Global.RedisConnection = ConnectionMultiplexer.Connect(
                          Settings.Deployment.RedisConnectionString);
                  }
              }
          }
          return Global.RedisConnection;
      }
  </code></pre>