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

This commit is contained in:
zpc 2026-04-01 19:47:20 +08:00
parent c227256015
commit 356bb074d5

View File

@ -162,18 +162,42 @@ namespace ZR.Service.Liveforum
/// <returns>清除的缓存key数量</returns>
public int ClearAllFlowerCache()
{
if (RedisServer.WebApiCache == null)
var logger = NLog.LogManager.GetCurrentClassLogger();
// 按需获取WebAPI Redis连接不依赖启动时初始化
var webApiRedis = RedisServer.WebApiCache;
if (webApiRedis == null)
{
throw new Exception("WebAPI Redis未配置请检查appsettings.json中的RedisServer:WebApiCache配置");
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;
}
var keys = RedisServer.WebApiCache.Keys("flower_count:Streamer:*");
var keys = webApiRedis.Keys("flower_count:Streamer:*");
logger.Info("找到 {0} 个flower_count:Streamer:* 缓存key", keys?.Length ?? 0);
if (keys == null || keys.Length == 0)
{
return 0;
}
RedisServer.WebApiCache.Del(keys);
webApiRedis.Del(keys);
logger.Info("已清除 {0} 个送花缓存key", keys.Length);
return keys.Length;
}