From c92b909211c3df75c14b7b0e55f8a399c5f4b81f Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Thu, 14 Mar 2024 16:17:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=BC=93=E5=AD=98=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/Djy.Common/Tools/Redis.cs | 30 ++++++++++++------- .../Controllers/CommonController.cs | 27 +++++++++++++++-- .../Milldlewares/CommonDataCacheMiddleware.cs | 2 +- .../FolderProfile-Windows.pubxml.user | 2 +- .../FolderProfile-linux.pubxml.user | 2 +- web/djy_AfrApi/Startup.cs | 4 +-- web/djy_AfrApi/djy_AfrApi.csproj | 1 - 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/web/Djy.Common/Tools/Redis.cs b/web/Djy.Common/Tools/Redis.cs index d09d6a6..9037125 100644 --- a/web/Djy.Common/Tools/Redis.cs +++ b/web/Djy.Common/Tools/Redis.cs @@ -17,15 +17,18 @@ namespace Common.Tools /// /// Redis 地址 默认使用 sysOptionConfig.Webconfig.Redis 配置信息的 /// - public static string RedisContext { set { + public static string RedisContext + { + set + { _RedisContext = value; } get { return _RedisContext; } } - /// - /// rendisDB - /// + /// + /// rendisDB + /// public static RedisClient DbRedis = new RedisClient(RedisContext); /// /// 删除单个键值对 @@ -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; } /// /// 清理统计redis键值 谨慎清理建议指定特定时间执行一次 /// /// - public static long RedisClenaRuncount() { - return RedisClena("runcount_*"); + public static long RedisClenaRuncount() + { + return RedisClena("runcount_*"); } /// ///增加 通过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; } } diff --git a/web/djy_AfrApi/Controllers/CommonController.cs b/web/djy_AfrApi/Controllers/CommonController.cs index bb9c8ef..c205610 100644 --- a/web/djy_AfrApi/Controllers/CommonController.cs +++ b/web/djy_AfrApi/Controllers/CommonController.cs @@ -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 } + /// + /// 清除所有Redis缓存 + /// + [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(); + } + ///// ///// 下拉获取省份 diff --git a/web/djy_AfrApi/Milldlewares/CommonDataCacheMiddleware.cs b/web/djy_AfrApi/Milldlewares/CommonDataCacheMiddleware.cs index 4053b5c..ff4bc43 100644 --- a/web/djy_AfrApi/Milldlewares/CommonDataCacheMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/CommonDataCacheMiddleware.cs @@ -56,7 +56,7 @@ namespace djy_AfrApi.Milldlewares Response response = JsonConvert.DeserializeObject(responseBody); if (response.Code == 200) { - YsRedisHelp.RedisSet(redisKey, responseBody, 86400); + YsRedisHelp.RedisSet(redisKey, responseBody, 60 * 5); } // 将响应内容写回原始响应流 diff --git a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user index 921f4a2..5e07ac4 100644 --- a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user +++ b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user @@ -6,7 +6,7 @@ <_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\ - 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; + 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; \ No newline at end of file diff --git a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-linux.pubxml.user b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-linux.pubxml.user index eee4f20..3ddca77 100644 --- a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-linux.pubxml.user +++ b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-linux.pubxml.user @@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. <_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-linux\ - 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; + 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; \ No newline at end of file diff --git a/web/djy_AfrApi/Startup.cs b/web/djy_AfrApi/Startup.cs index 9149390..7594650 100644 --- a/web/djy_AfrApi/Startup.cs +++ b/web/djy_AfrApi/Startup.cs @@ -74,8 +74,8 @@ namespace djy_AfrApi sysOptionConfig._Configuration = Configuration; // עredisͻ - RedisClient cli = new RedisClient(sysOptionConfig.Webconfig.Redis + ",defaultDatabase=" + sysOptionConfig.Webconfig.RedisDb); - services.AddSingleton(cli); + //RedisClient cli = new RedisClient(sysOptionConfig.Webconfig.Redis + ",defaultDatabase=" + sysOptionConfig.Webconfig.RedisDb); + //services.AddSingleton(cli); services.AddAuthentication("Bearer").AddJwtBearer("Bearer", option => { diff --git a/web/djy_AfrApi/djy_AfrApi.csproj b/web/djy_AfrApi/djy_AfrApi.csproj index 34cd2cf..2c555a7 100644 --- a/web/djy_AfrApi/djy_AfrApi.csproj +++ b/web/djy_AfrApi/djy_AfrApi.csproj @@ -11,7 +11,6 @@ -