清缓存的接口

master
zhangxiaofeng 8 months ago
parent 3a5948c0e7
commit c92b909211

@ -17,15 +17,18 @@ namespace Common.Tools
/// <summary>
/// Redis 地址 默认使用 sysOptionConfig.Webconfig.Redis 配置信息的
/// </summary>
public static string RedisContext { set {
public static string RedisContext
{
set
{
_RedisContext = value;
}
get { return _RedisContext; }
}
/// <summary>
/// rendisDB
/// </summary>
/// <summary>
/// rendisDB
/// </summary>
public static RedisClient DbRedis = new RedisClient(RedisContext);
/// <summary>
/// 删除单个键值对
@ -45,15 +48,19 @@ namespace Common.Tools
{
var keylist = DbRedis.Keys(keymodel);
return DbRedis.Del(keylist);
if (keylist != null && keylist.Any())
{
return DbRedis.Del(keylist);
}
return 0;
}
/// <summary>
/// 清理统计redis键值 谨慎清理建议指定特定时间执行一次
/// </summary>
/// <returns></returns>
public static long RedisClenaRuncount() {
return RedisClena("runcount_*");
public static long RedisClenaRuncount()
{
return RedisClena("runcount_*");
}
/// <summary>
///增加 通过redis统计计数
@ -93,10 +100,11 @@ namespace Common.Tools
{
return listarry.ToList().ConvertAll(s => long.Parse(s)).Count(s => s >= _time);
}
else {
return 0;
else
{
return 0;
}
}
catch { return 0; }
}

@ -1,4 +1,5 @@
using Common.Utilities;
using Common.Tools;
using Common.Utilities;
using djy.IService.Afr;
using djy.Model.AmsDto;
using djy_AfrApi.Attributes;
@ -6,13 +7,15 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace djy_AfrApi.Controllers.Common
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class CommonController
public class CommonController : ApiBase
{
private readonly IAfrService ser;
@ -196,6 +199,26 @@ namespace djy_AfrApi.Controllers.Common
}
/// <summary>
/// 清除所有Redis缓存
/// </summary>
[AllowAnonymous]
[HttpGet("[action]")]
public Response ClearCache()
{
var type = typeof(CommonController);
MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
foreach (MethodInfo item in methods)
{
var attr = item.GetCustomAttributes(typeof(RedisCachingAttribute));
if (attr.Any())
{
YsRedisHelp.RedisClena(item.Name + "Cache");
}
}
return SuccessResp();
}
///// <summary>
///// 下拉获取省份

@ -56,7 +56,7 @@ namespace djy_AfrApi.Milldlewares
Response response = JsonConvert.DeserializeObject<Response>(responseBody);
if (response.Code == 200)
{
YsRedisHelp.RedisSet<string>(redisKey, responseBody, 86400);
YsRedisHelp.RedisSet<string>(redisKey, responseBody, 60 * 5);
}
// 将响应内容写回原始响应流

@ -6,7 +6,7 @@
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\</_PublishTargetUrl>
<History>True|2024-02-04T06:12:20.2942963Z;True|2024-02-04T14:09:16.2854775+08:00;True|2024-01-25T10:01:36.0649321+08:00;True|2024-01-23T11:01:55.0706970+08:00;True|2024-01-19T13:34:45.2044545+08:00;True|2024-01-19T11:20:41.9920968+08:00;True|2024-01-08T15:50:46.8011898+08:00;True|2024-01-05T17:51:52.2695558+08:00;True|2024-01-05T17:04:21.5306695+08:00;True|2024-01-05T16:48:05.1050469+08:00;True|2024-01-05T15:13:30.4657789+08:00;True|2024-01-05T15:00:49.5985418+08:00;True|2024-01-05T13:48:06.1634940+08:00;True|2024-01-05T11:59:09.7697688+08:00;True|2024-01-05T11:33:19.2093394+08:00;True|2024-01-05T11:27:31.2454199+08:00;True|2024-01-05T11:20:20.5464568+08:00;True|2024-01-04T18:36:38.8259124+08:00;True|2024-01-04T15:54:57.9348895+08:00;True|2024-01-04T15:44:34.6535493+08:00;False|2024-01-04T15:44:20.9673752+08:00;True|2024-01-04T11:14:33.4379160+08:00;True|2024-01-03T21:54:40.3579096+08:00;True|2024-01-03T21:52:09.6604718+08:00;True|2024-01-03T16:04:13.6208067+08:00;True|2024-01-03T15:07:08.9376581+08:00;True|2024-01-02T10:57:59.7067270+08:00;True|2024-01-02T10:28:44.8223638+08:00;True|2023-12-29T17:26:12.9612280+08:00;</History>
<History>True|2024-02-29T01:31:35.8401645Z;True|2024-02-29T09:22:56.0822260+08:00;True|2024-02-04T14:12:20.2942963+08:00;True|2024-02-04T14:09:16.2854775+08:00;True|2024-01-25T10:01:36.0649321+08:00;True|2024-01-23T11:01:55.0706970+08:00;True|2024-01-19T13:34:45.2044545+08:00;True|2024-01-19T11:20:41.9920968+08:00;True|2024-01-08T15:50:46.8011898+08:00;True|2024-01-05T17:51:52.2695558+08:00;True|2024-01-05T17:04:21.5306695+08:00;True|2024-01-05T16:48:05.1050469+08:00;True|2024-01-05T15:13:30.4657789+08:00;True|2024-01-05T15:00:49.5985418+08:00;True|2024-01-05T13:48:06.1634940+08:00;True|2024-01-05T11:59:09.7697688+08:00;True|2024-01-05T11:33:19.2093394+08:00;True|2024-01-05T11:27:31.2454199+08:00;True|2024-01-05T11:20:20.5464568+08:00;True|2024-01-04T18:36:38.8259124+08:00;True|2024-01-04T15:54:57.9348895+08:00;True|2024-01-04T15:44:34.6535493+08:00;False|2024-01-04T15:44:20.9673752+08:00;True|2024-01-04T11:14:33.4379160+08:00;True|2024-01-03T21:54:40.3579096+08:00;True|2024-01-03T21:52:09.6604718+08:00;True|2024-01-03T16:04:13.6208067+08:00;True|2024-01-03T15:07:08.9376581+08:00;True|2024-01-02T10:57:59.7067270+08:00;True|2024-01-02T10:28:44.8223638+08:00;True|2023-12-29T17:26:12.9612280+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-linux\</_PublishTargetUrl>
<History>True|2024-02-04T06:34:07.9001297Z;True|2024-01-29T17:48:24.1888961+08:00;True|2024-01-29T14:55:22.3697340+08:00;True|2024-01-26T15:18:26.3618341+08:00;True|2024-01-26T14:55:05.3552141+08:00;True|2024-01-25T17:09:15.3482577+08:00;False|2024-01-25T17:08:55.2779489+08:00;True|2024-01-25T16:46:48.0925564+08:00;</History>
<History>True|2024-03-14T08:13:19.0717213Z;True|2024-03-08T11:13:30.3644089+08:00;True|2024-02-29T08:54:35.9996054+08:00;True|2024-02-04T14:34:07.9001297+08:00;True|2024-01-29T17:48:24.1888961+08:00;True|2024-01-29T14:55:22.3697340+08:00;True|2024-01-26T15:18:26.3618341+08:00;True|2024-01-26T14:55:05.3552141+08:00;True|2024-01-25T17:09:15.3482577+08:00;False|2024-01-25T17:08:55.2779489+08:00;True|2024-01-25T16:46:48.0925564+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

@ -74,8 +74,8 @@ namespace djy_AfrApi
sysOptionConfig._Configuration = Configuration;
// 注入redis客户端
RedisClient cli = new RedisClient(sysOptionConfig.Webconfig.Redis + ",defaultDatabase=" + sysOptionConfig.Webconfig.RedisDb);
services.AddSingleton<IRedisClient>(cli);
//RedisClient cli = new RedisClient(sysOptionConfig.Webconfig.Redis + ",defaultDatabase=" + sysOptionConfig.Webconfig.RedisDb);
//services.AddSingleton<IRedisClient>(cli);
services.AddAuthentication("Bearer").AddJwtBearer("Bearer", option =>
{

@ -11,7 +11,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FreeRedis" Version="1.2.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.17" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.7" />

Loading…
Cancel
Save