新增加redis方法
This commit is contained in:
parent
072db6b4b3
commit
e7dcdb2c58
@ -84,7 +84,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
mailHelper.SendMail(toUsers, sendEmailVo.Subject, sendEmailVo.Content, sendEmailVo.FileUrl, sendEmailVo.HtmlContent);
|
||||||
|
|
||||||
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}");
|
logger.Info($"发送邮件{JsonConvert.SerializeObject(sendEmailVo)}");
|
||||||
|
|
||||||
return SUCCESS(true);
|
return SUCCESS(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,10 +11,12 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using ZR.Admin.WebApi.Extensions;
|
using ZR.Admin.WebApi.Extensions;
|
||||||
using ZR.Admin.WebApi.Filters;
|
using ZR.Admin.WebApi.Filters;
|
||||||
using ZR.Admin.WebApi.Framework;
|
using ZR.Admin.WebApi.Framework;
|
||||||
using ZR.Admin.WebApi.Middleware;
|
using ZR.Admin.WebApi.Middleware;
|
||||||
|
using ZR.Common.Cache;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi
|
namespace ZR.Admin.WebApi
|
||||||
{
|
{
|
||||||
@ -137,6 +139,12 @@ namespace ZR.Admin.WebApi
|
|||||||
services.AddTaskSchedulers();
|
services.AddTaskSchedulers();
|
||||||
//³õʼ»¯db
|
//³õʼ»¯db
|
||||||
DbExtension.AddDb(configuration);
|
DbExtension.AddDb(configuration);
|
||||||
|
|
||||||
|
//×¢²áREDIS ·þÎñ
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
RedisServer.Initalize();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,5 +53,9 @@
|
|||||||
//ÐÒé
|
//ÐÒé
|
||||||
"Smtp": "smtp.qq.com",
|
"Smtp": "smtp.qq.com",
|
||||||
"Port": 587
|
"Port": 587
|
||||||
|
},
|
||||||
|
"RedisServer": {
|
||||||
|
"Cache": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=cache:",
|
||||||
|
"Session": "127.0.0.1:6379,defaultDatabase=0,poolsize=50,ssl=false,writeBuffer=10240,prefix=session:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Web;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 数据缓存操作类 author by zhaorui 2021-3-6
|
|
||||||
/// </summary>
|
|
||||||
namespace ZR.Common
|
namespace ZR.Common
|
||||||
{
|
{
|
||||||
public class CacheHelper
|
public class CacheHelper
|
||||||
@ -19,11 +14,6 @@ namespace ZR.Common
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 全局缓存时间
|
|
||||||
/// </summary>
|
|
||||||
public static int CacheTime = 5; //ConfigHelper.GetConfigInt("CacheTime");
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取缓存
|
/// 获取缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -46,7 +36,6 @@ namespace ZR.Common
|
|||||||
public static object GetCache(string CacheKey)
|
public static object GetCache(string CacheKey)
|
||||||
{
|
{
|
||||||
return Cache.Get<object>(CacheKey);
|
return Cache.Get<object>(CacheKey);
|
||||||
//return HttpRuntime.Cache[CacheKey];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static object Get(string CacheKey)
|
public static object Get(string CacheKey)
|
||||||
@ -59,9 +48,9 @@ namespace ZR.Common
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="CacheKey">key</param>
|
/// <param name="CacheKey">key</param>
|
||||||
/// <param name="objObject">值</param>
|
/// <param name="objObject">值</param>
|
||||||
public static void SetCache(string CacheKey, object objObject)
|
public static object SetCache(string CacheKey, object objObject)
|
||||||
{
|
{
|
||||||
Cache.Set(CacheKey, objObject);
|
return Cache.Set(CacheKey, objObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,9 +59,9 @@ namespace ZR.Common
|
|||||||
/// <param name="CacheKey">key</param>
|
/// <param name="CacheKey">key</param>
|
||||||
/// <param name="objObject">值</param>
|
/// <param name="objObject">值</param>
|
||||||
/// <param name="Timeout">过期时间(分钟)</param>
|
/// <param name="Timeout">过期时间(分钟)</param>
|
||||||
public static void SetCache(string CacheKey, object objObject, int Timeout)
|
public static object SetCache(string CacheKey, object objObject, int Timeout)
|
||||||
{
|
{
|
||||||
Cache.Set(CacheKey, objObject, DateTime.Now.AddMinutes(Timeout));
|
return Cache.Set(CacheKey, objObject, DateTime.Now.AddMinutes(Timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,9 +82,9 @@ namespace ZR.Common
|
|||||||
/// <param name="objObject">值</param>
|
/// <param name="objObject">值</param>
|
||||||
/// <param name="absoluteExpiration">过期时间</param>
|
/// <param name="absoluteExpiration">过期时间</param>
|
||||||
/// <param name="slidingExpiration">过期时间间隔</param>
|
/// <param name="slidingExpiration">过期时间间隔</param>
|
||||||
public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
|
public static object SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
|
||||||
{
|
{
|
||||||
Cache.Set(CacheKey, objObject, absoluteExpiration);
|
return Cache.Set(CacheKey, objObject, absoluteExpiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -103,7 +92,7 @@ namespace ZR.Common
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="CacheKey"></param>
|
/// <param name="CacheKey"></param>
|
||||||
/// <param name="objObject"></param>
|
/// <param name="objObject"></param>
|
||||||
/// <param name="seconds">超过多少秒后过期</param>
|
/// <param name="Seconds">超过多少秒后过期</param>
|
||||||
public static void SetCacheDateTime(string CacheKey, object objObject, long Seconds)
|
public static void SetCacheDateTime(string CacheKey, object objObject, long Seconds)
|
||||||
{
|
{
|
||||||
Cache.Set(CacheKey, objObject, DateTime.Now.AddSeconds(Seconds));
|
Cache.Set(CacheKey, objObject, DateTime.Now.AddSeconds(Seconds));
|
||||||
|
|||||||
17
ZR.Common/Cache/RedisServer.cs
Normal file
17
ZR.Common/Cache/RedisServer.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using CSRedis;
|
||||||
|
using Infrastructure;
|
||||||
|
|
||||||
|
namespace ZR.Common.Cache
|
||||||
|
{
|
||||||
|
public class RedisServer
|
||||||
|
{
|
||||||
|
public static CSRedisClient Cache;
|
||||||
|
public static CSRedisClient Session;
|
||||||
|
|
||||||
|
public static void Initalize()
|
||||||
|
{
|
||||||
|
Cache = new CSRedisClient(ConfigUtils.Instance.GetConfig("RedisServer:Cache"));
|
||||||
|
Session = new CSRedisClient(ConfigUtils.Instance.GetConfig("RedisServer:Session"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
|
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
|
||||||
|
<PackageReference Include="CSRedisCore" Version="3.6.5" />
|
||||||
<PackageReference Include="EPPlus" Version="5.8.3" />
|
<PackageReference Include="EPPlus" Version="5.8.3" />
|
||||||
<PackageReference Include="MailKit" Version="3.0.0" />
|
<PackageReference Include="MailKit" Version="3.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user