Raghu
Raghu

Reputation: 11

Redis cache showing system err cause of timeout redis connection with default azure credentials

We are using default azure credentials to connect the Redis cache we are using below connection and given all permissions include DataAccessConfiguration here is my code

private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
  {
      string workloadIdentityIsEnabled = ConfigurationUtil.GetSetting("WorkloadIdentityConfigIsEnabled");

      if (Convert.ToBoolean(workloadIdentityIsEnabled))
      {
          var credential = new DefaultAzureCredential();
          string cacheConnectionEndpoint = ConfigurationUtil.GetSetting("RedisCacheConnectionString"); 
          var configurationOptions = ConfigurationOptions.Parse($"{cacheConnectionEndpoint}:6380").ConfigureForAzureWithTokenCredentialAsync(credential);
          configurationOptions.Result.AbortOnConnectFail = false;
          configurationOptions.Result.SyncTimeout = 60000;
          return ConnectionMultiplexer.Connect(configurationOptions.Result);
      }
      else
      {
          string cacheConnectionString = ConfigurationUtil.GetSetting("RedisCacheConnectionString");
          return ConnectionMultiplexer.Connect(cacheConnectionString);
      }
  });

  public static ConnectionMultiplexer Connection
  {
      get
      {
          try
          {
              return lazyConnection.Value;
          }
          catch
          {
              return null;
          }
      }
  }

if it is run fast it's working fine if any delay or any debug breaks it's showing error.

Upvotes: 0

Views: 31

Answers (0)

Related Questions