This commit is contained in:
parent
c227256015
commit
356bb074d5
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user