Add some fixes in cache settings
This commit is contained in:
		| @@ -21,8 +21,6 @@ namespace Core.Blueprint.Caching.Configuration | ||||
|         { | ||||
|             // TODO for the following variable we'll need to add in the appsettings.json the following config: "UseRedisCache": true, | ||||
|             bool useRedis = configuration.GetValue<bool>("UseRedisCache"); | ||||
|             //TODO decide wheter to use appsettings or the following ENV variable | ||||
|             useRedis = Environment.GetEnvironmentVariable("CORE_BLUEPRINT_PACKAGES_USE_REDIS")?.ToLower() == "true"; | ||||
|  | ||||
|             if (useRedis) | ||||
|             { | ||||
|   | ||||
| @@ -35,14 +35,29 @@ namespace Core.Blueprint.Caching | ||||
|         /// <param name="connectionString">The Redis connection string.</param> | ||||
|         /// <returns>An <see cref="IDatabase"/> instance representing the Redis cache database.</returns> | ||||
|         /// <exception cref="Exception">Thrown when the connection to Redis fails.</exce | ||||
|         async Task<IDatabase> InitializeRedisAsync(string connectionString) | ||||
|         public async Task<IDatabase> InitializeRedisAsync(string connectionString) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var configurationOptions = await ConfigurationOptions.Parse($"{connectionString}") | ||||
|                     .ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()); | ||||
|                 var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty; | ||||
|  | ||||
|                 ConfigurationOptions configurationOptions; | ||||
|  | ||||
|                 if (environment.Equals("Local", StringComparison.OrdinalIgnoreCase)) | ||||
|                 { | ||||
|                     // Use simple local Redis config | ||||
|                     configurationOptions = ConfigurationOptions.Parse(connectionString); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // Use Azure Redis config | ||||
|                     configurationOptions = await ConfigurationOptions | ||||
|                         .Parse(connectionString) | ||||
|                         .ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()); | ||||
|                 } | ||||
|  | ||||
|                 configurationOptions.AbortOnConnectFail = false; | ||||
|  | ||||
|                 var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); | ||||
|  | ||||
|                 _logger.LogInformation("Successfully connected to Redis."); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Oscar Morales
					Oscar Morales