From f3a757d33d6128d210504c9aceb56f2e1fb7d6e1 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Sat, 1 Jun 2024 10:53:21 +0300 Subject: [PATCH] feat: add redis --- .../AppConfig/CacheConfiguration.cs | 23 +++++++++++++++++++ Endpoint/Endpoint.csproj | 1 + 2 files changed, 24 insertions(+) create mode 100644 Endpoint/Configuration/AppConfig/CacheConfiguration.cs diff --git a/Endpoint/Configuration/AppConfig/CacheConfiguration.cs b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs new file mode 100644 index 0000000..7a1954c --- /dev/null +++ b/Endpoint/Configuration/AppConfig/CacheConfiguration.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Mirea.Api.Endpoint.Configuration.General.Settings; + +namespace Mirea.Api.Endpoint.Configuration.AppConfig; + +public static class CacheConfiguration +{ + public static IServiceCollection AddCustomRedis(this IServiceCollection services, IConfiguration configuration) + { + var cache = configuration.Get(); + if (cache?.TypeDatabase == CacheSettings.CacheEnum.Redis) + { + services.AddStackExchangeRedisCache(options => + { + options.Configuration = cache.ConnectionString; + options.InstanceName = "mirea_"; + }); + } + + return services; + } +} \ No newline at end of file diff --git a/Endpoint/Endpoint.csproj b/Endpoint/Endpoint.csproj index 26fc0a3..bb33b99 100644 --- a/Endpoint/Endpoint.csproj +++ b/Endpoint/Endpoint.csproj @@ -29,6 +29,7 @@ +