StackExchange.Redis with Azure Redis is unusably slow or throws timeout errors StackExchange.Redis with Azure Redis is unusably slow or throws timeout errors azure azure

StackExchange.Redis with Azure Redis is unusably slow or throws timeout errors


Here is the recommended pattern, from the Azure Redis Cache documentation:

private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() => {    return ConnectionMultiplexer.Connect("mycache.redis.cache.windows.net,abortConnect=false,ssl=true,password=...");});public static ConnectionMultiplexer Connection {    get {        return lazyConnection.Value;    }}

A few important points:

  • It uses Lazy<T> to handle thread-safe initialization
  • It sets "abortConnect=false", which means if the initial connect attempt fails, the ConnectionMultiplexer will silently retry in the background rather than throw an exception.
  • It does not check the IsConnected property, since ConnectionMultiplexer will automatically retry in the background if the connection is dropped.


I was having similar issues. Redis cache was unusually slow but was definitely caching. In some cases, it took 20-40 seconds to load a page.

I realized that the cache server was in a different location than the site's. I updated the cache server to live in the same location as the website and now everything works as expected.

That same page now loads in 4-6 seconds.

Good luck to anyone else who's having these issues.


The problem is how the connection object created and used. we faced exact problem initially and fixed with a single connection object getting used across all web requests. And we check is it null or connected in session start for graceful re creating object. that fixed the issue.

Note: Also check in which Zone of Azure your Redis Cache instance is running and Which Zone your Web Server exist. It is better to maintain both in Same Zone

In Global.ascx.cs file

public static ConnectionMultiplexer RedisConnection;public static IDatabase RedisCacheDb;protected void Session_Start(object sender, EventArgs e)    {        if (ConfigurationManager.ConnectionStrings["RedisCache"] != null)        {            if (RedisConnection == null || !RedisConnection.IsConnected)            {                RedisConnection = ConnectionMultiplexer.Connect(ConfigurationManager.ConnectionStrings["RedisCache"].ConnectionString);            }            RedisCacheDb = RedisConnection.GetDatabase();        }    }