diff --git a/server/admin/ZrAdminNetCore/Infrastructure/Cache/RedisServer.cs b/server/admin/ZrAdminNetCore/Infrastructure/Cache/RedisServer.cs index 02e171f..a6179b7 100644 --- a/server/admin/ZrAdminNetCore/Infrastructure/Cache/RedisServer.cs +++ b/server/admin/ZrAdminNetCore/Infrastructure/Cache/RedisServer.cs @@ -14,9 +14,15 @@ namespace ZR.Common.Cache Cache = new CSRedisClient(AppSettings.GetConfig("RedisServer:Cache")); Session = new CSRedisClient(AppSettings.GetConfig("RedisServer:Session")); var webApiCacheConfig = AppSettings.GetConfig("RedisServer:WebApiCache"); + Console.WriteLine($"[RedisServer] WebApiCache配置: [{webApiCacheConfig ?? "(null)"}]"); if (!string.IsNullOrEmpty(webApiCacheConfig)) { WebApiCache = new CSRedisClient(webApiCacheConfig); + Console.WriteLine("[RedisServer] WebApiCache已初始化"); + } + else + { + Console.WriteLine("[RedisServer] 警告: WebApiCache未配置,清空送花缓存功能将不可用"); } } } diff --git a/server/admin/ZrAdminNetCore/ZR.Service/Liveforum/T_StreamersService.cs b/server/admin/ZrAdminNetCore/ZR.Service/Liveforum/T_StreamersService.cs index a4214c1..ed48fd3 100644 --- a/server/admin/ZrAdminNetCore/ZR.Service/Liveforum/T_StreamersService.cs +++ b/server/admin/ZrAdminNetCore/ZR.Service/Liveforum/T_StreamersService.cs @@ -164,32 +164,15 @@ namespace ZR.Service.Liveforum { var logger = NLog.LogManager.GetCurrentClassLogger(); - // 按需获取WebAPI Redis连接,不依赖启动时初始化 var webApiRedis = RedisServer.WebApiCache; if (webApiRedis == null) { - var config = Infrastructure.AppSettings.GetConfig("RedisServer:WebApiCache"); - logger.Info("RedisServer:WebApiCache 配置值: [{0}], IsNull: {1}, IsEmpty: {2}", - config ?? "(null)", config == null, string.IsNullOrEmpty(config)); - - // 打印其他Redis配置做对比 - var cacheConfig = Infrastructure.AppSettings.GetConfig("RedisServer:Cache"); - var openConfig = Infrastructure.AppSettings.GetConfig("RedisServer:open"); - logger.Info("RedisServer:Cache 配置值: [{0}]", cacheConfig ?? "(null)"); - logger.Info("RedisServer:open 配置值: [{0}]", openConfig ?? "(null)"); - - if (string.IsNullOrEmpty(config)) - { - throw new Exception($"WebAPI Redis未配置。RedisServer:open=[{openConfig}], RedisServer:Cache=[{(string.IsNullOrEmpty(cacheConfig) ? "(空)" : "已配置")}], RedisServer:WebApiCache=[(空)]。请在appsettings.json的RedisServer节点下添加WebApiCache配置项"); - } - - logger.Info("正在创建WebAPI Redis连接: {0}", config); - webApiRedis = new CSRedis.CSRedisClient(config); - RedisServer.WebApiCache = webApiRedis; + logger.Error("RedisServer.WebApiCache 为 null,请检查:1) appsettings.json 中是否配置了 RedisServer:WebApiCache 2) 配置后是否重启了服务"); + throw new Exception("WebAPI Redis未初始化。请确认appsettings.json中已配置RedisServer:WebApiCache,并重启管理后台服务"); } var keys = webApiRedis.Keys("flower_count:Streamer:*"); - logger.Info("找到 {0} 个flower_count:Streamer:* 缓存key", keys?.Length ?? 0); + logger.Info("找到 {0} 个 flower_count:Streamer:* 缓存key", keys?.Length ?? 0); if (keys == null || keys.Length == 0) {