You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
994 B

using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
using Znyc.CloudCar.Caching;
using Znyc.CloudCar.Configuration;
namespace Znyc.CloudCar.Core.Config
{
/// <summary>
/// Redis缓存,启动服务
/// </summary>
public static class RedisCacheSetup
{
public static void AddRedisCacheSetup(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentException(nameof(services));
}
services.AddSingleton(sp =>
{
string redisConfiguration = AppSettingsConstVars.RedisConfigConnectionString;
var configuration = ConfigurationOptions.Parse(redisConfiguration, true);
configuration.ResolveDns = true;
return ConnectionMultiplexer.Connect(configuration);
});
services.AddTransient<IRedisOperationRepository, RedisOperationRepository>();
}
}
}