21
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
zpc 2026-04-01 19:52:28 +08:00
parent 356bb074d5
commit f8cf88cbe1
2 changed files with 9 additions and 20 deletions

View File

@ -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未配置清空送花缓存功能将不可用");
}
}
}

View File

@ -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)
{