feat: 支持默认启用redis
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Medallion.Threading;
|
||||
using Medallion.Threading.Redis;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StackExchange.Redis;
|
||||
using Volo.Abp.AspNetCore.SignalR;
|
||||
@@ -42,14 +43,18 @@ namespace Yi.Framework.Rbac.Domain
|
||||
//配置阿里云短信
|
||||
Configure<AliyunOptions>(configuration.GetSection(nameof(AliyunOptions)));
|
||||
|
||||
//分布式锁
|
||||
context.Services.AddSingleton<IDistributedLockProvider>(sp =>
|
||||
//分布式锁,需要redis
|
||||
if (configuration.GetSection("Redis").GetValue<bool>("IsEnabled"))
|
||||
{
|
||||
var connection = ConnectionMultiplexer
|
||||
.Connect(configuration["Redis:Configuration"]);
|
||||
return new
|
||||
RedisDistributedSynchronizationProvider(connection.GetDatabase());
|
||||
});
|
||||
context.Services.AddSingleton<IDistributedLockProvider>(sp =>
|
||||
{
|
||||
var connection = ConnectionMultiplexer
|
||||
.Connect(configuration["Redis:Configuration"]);
|
||||
return new
|
||||
RedisDistributedSynchronizationProvider(connection.GetDatabase());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,12 +185,12 @@ namespace Yi.Abp.Application.Services
|
||||
/// <summary>
|
||||
/// 分布式送abp版本:abp套了一层娃。但是纯粹鸡肋,不建议使用这个
|
||||
/// </summary>
|
||||
public IAbpDistributedLock AbpDistributedLock { get; set; }
|
||||
public IAbpDistributedLock AbpDistributedLock => LazyServiceProvider.LazyGetService<IAbpDistributedLock>();
|
||||
|
||||
/// <summary>
|
||||
/// 分布式锁推荐使用版本:yyds,分布式锁永远的神!
|
||||
/// </summary>
|
||||
public IDistributedLockProvider DistributedLock { get; set; }
|
||||
public IDistributedLockProvider DistributedLock => LazyServiceProvider.LazyGetService<IDistributedLockProvider>();
|
||||
|
||||
/// <summary>
|
||||
/// 分布式锁
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace Yi.Abp.Web
|
||||
var redisConfiguration = configuration["Redis:Configuration"];
|
||||
context.Services.AddHangfire(config=>
|
||||
{
|
||||
bool.TryParse( configuration["Redis:IsEnabled"], out var redisEnabled);
|
||||
var redisEnabled=configuration.GetSection("Redis").GetValue<bool>("IsEnabled");
|
||||
if (redisEnabled)
|
||||
{
|
||||
var jobDb=configuration.GetSection("Redis").GetValue<int>("JobDb");
|
||||
|
||||
Reference in New Issue
Block a user