mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:13:26 +08:00
# 2022-01-24
### 1.3.4 开源社区版(会员专业版同步修改): 【修复】修复redis长期ping和info导致连接数无限增长,进而内存被耗尽的bug。 【修复】修复未填写redis链接或链接失败报错提示端口错误。 【优化】修改hangfire定时任务全部规则为cron表达式。 ### 0.1.3 会员专业版: 同上。
This commit is contained in:
@@ -20,6 +20,7 @@ using Hangfire.Redis;
|
||||
using Hangfire.SqlServer;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SqlSugar;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
@@ -28,6 +29,9 @@ namespace CoreCms.Net.Core.Config
|
||||
/// </summary>
|
||||
public static class HangFireSetup
|
||||
{
|
||||
private static ConnectionMultiplexer _redis;
|
||||
|
||||
|
||||
public static void AddHangFireSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
@@ -36,9 +40,13 @@ namespace CoreCms.Net.Core.Config
|
||||
var isEnabledRedis = AppSettingsConstVars.RedisUseTimedTask;
|
||||
if (isEnabledRedis)
|
||||
{
|
||||
services.AddHangfire(x => x.UseRedisStorage(AppSettingsConstVars.RedisConfigConnectionString, new RedisStorageOptions()
|
||||
var configuration = ConfigurationOptions.Parse(AppSettingsConstVars.RedisConfigConnectionString, true);
|
||||
_redis = ConnectionMultiplexer.Connect(configuration);
|
||||
var db = _redis.GetDatabase();
|
||||
|
||||
services.AddHangfire(x => x.UseRedisStorage(_redis, new RedisStorageOptions()
|
||||
{
|
||||
Db = 10,
|
||||
Db = db.Database, //建议根据
|
||||
SucceededListSize = 500,//后续列表中的最大可见后台作业,以防止它无限增长。
|
||||
DeletedListSize = 500,//删除列表中的最大可见后台作业,以防止其无限增长。
|
||||
InvisibilityTimeout = TimeSpan.FromMinutes(30),
|
||||
@@ -81,8 +89,7 @@ namespace CoreCms.Net.Core.Config
|
||||
options.ServerTimeout = TimeSpan.FromMinutes(4);
|
||||
options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点,一般任务可以配置默认时间,默认15秒
|
||||
options.ShutdownTimeout = TimeSpan.FromMinutes(5); //超时时间
|
||||
//options.WorkerCount = Math.Max(Environment.ProcessorCount, 2); //工作线程数,当前允许的最大线程,默认20
|
||||
options.WorkerCount = 2; //工作线程数,当前允许的最大线程,默认20
|
||||
options.WorkerCount = Math.Max(Environment.ProcessorCount, 20); //工作线程数,当前允许的最大线程,默认20
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ namespace CoreCms.Net.Core.Config
|
||||
services.ConfigurationSugar(db =>
|
||||
{
|
||||
db.CurrentConnectionConfig.InitKeyType = InitKeyType.Attribute;
|
||||
db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
|
||||
{
|
||||
//判断是否开启redis设置二级缓存方式
|
||||
DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache()
|
||||
};
|
||||
//db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
|
||||
//{
|
||||
// //判断是否开启redis设置二级缓存方式
|
||||
// DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache()
|
||||
//};
|
||||
|
||||
//执行SQL 错误事件,可监控sql(暂时屏蔽,需要可开启)
|
||||
//db.Aop.OnLogExecuting = (sql, p) =>
|
||||
|
||||
Reference in New Issue
Block a user