title: StackExchange.Redis StringGet Timeouts
body: <p><strong>Disclaimer</strong>: I am quite new to Redis and StackExchange.Redis client.</p>
  
  <p><strong>Scenario</strong>: I've got an ASP.NET MVC web app that uses <a href="https://msdn.microsoft.com/en-us/library/azure/dn690522.aspx" rel="nofollow noreferrer">ASP.NET Session State Provider for Azure Redis Cache</a>.</p>
  
  <p>This works like a charm!</p>
  
  <p>Now, my controllers call my services layer (it's just a DLL reference but may become a Web Api call one day). I am trying to configure my redis client with Autofac as per below:</p>
  
  <pre><code>        var redis = ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["redis.connectionstring"]);
          builder.RegisterInstance(redis).AsSelf().SingleInstance();
          builder.RegisterType&lt;RedisCacheClient&gt;().As&lt;ICacheClient&gt;().WithParameter("db", redis.GetDatabase());
  </code></pre>
  
  <p>The connection is set up successfully and I can see a new client when I run <em>client list</em> on <em>redis-cli.exe</em>.</p>
  
  <p>My RedisCacheClient class is just a thin wrapper on <a href="https://github.com/StackExchange/StackExchange.Redis/blob/master/StackExchange.Redis/StackExchange/Redis/IDatabase.cs" rel="nofollow noreferrer">IDatabase</a>:</p>
  
  <pre><code>    public void Add(string key, object value)
      {
          _db.StringSet(key, Serialize(value));
      }
  
      public T Get&lt;T&gt;(string key)
      {
          byte[] buffer = _db.StringGet(key);
          T o = Deserialize&lt;T&gt;(buffer);
          return o;
      }
  
      private static byte[] Serialize(object o)
      {
          if (o == null)
          {
              throw new ArgumentNullException("Cannot cache null values.");
          }
          var binaryFormatter = new BinaryFormatter();
          using (var memoryStream = new MemoryStream())
          {
              binaryFormatter.Serialize(memoryStream, o);
              byte[] buffer = memoryStream.ToArray();
              return buffer;
          }
      }
  
      private static T Deserialize&lt;T&gt;(byte[] stream)
      {
          if (stream == null)
          {
              return default(T);
          }
          var binaryFormatter = new BinaryFormatter();
          using (var memoryStream = new MemoryStream(stream))
          {
              T result = (T)binaryFormatter.Deserialize(memoryStream);
              return result;
          }
      }
  </code></pre>
  
  <p><strong>Problem</strong>: I can store objects successfully but can never retrieve then! I keep getting connections timeout no matter what I do (current timeout is 30 secs).
  I've spent the last 4 hours trying to figure this out and no luck. Really struggling :(</p>
  
  <p>Some of the resources I have already gone through:
  <a href="http://azure.microsoft.com/blog/2015/02/10/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/" rel="nofollow noreferrer">http://azure.microsoft.com/blog/2015/02/10/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/</a></p>
  
  <p><a href="https://stackoverflow.com/questions/26727762/timeout-performing-set-key-inst-0-mgr-inactive-queue-2-qu-1-qs-1-qc-0">Timeout performing SET {Key}, inst: 0, mgr: Inactive, queue: 2, qu=1, qs=1, qc=0, wr=1/1, in=0/0</a></p>
  
  <p><a href="https://stackoverflow.com/questions/25416562/stackexchange-redis-with-azure-redis-is-unusably-slow-or-throws-timeout-errors">StackExchange.Redis with Azure Redis is unusably slow or throws timeout errors</a></p>
  
  <p><a href="https://stackoverflow.com/questions/26489197/azure-redis-cache-timeouts-on-get-calls">Azure Redis cache - timeouts on GET calls</a></p>
  
  <p><a href="https://github.com/StackExchange/StackExchange.Redis/issues/122" rel="nofollow noreferrer">https://github.com/StackExchange/StackExchange.Redis/issues/122</a></p>
  
  <p><a href="https://github.com/StackExchange/StackExchange.Redis/issues/83" rel="nofollow noreferrer">https://github.com/StackExchange/StackExchange.Redis/issues/83</a></p>
  
  <p>P.S: I get the very same behaviour running this locally or on azure.</p>