批量删除redis

This commit is contained in:
xiangheng
2024-10-29 16:14:38 +08:00
parent 04abdf9a05
commit f7dec7874d
6 changed files with 20 additions and 18 deletions

View File

@@ -52,16 +52,23 @@ func (c CacheUtil) GetCache(key interface{}, obj interface{}) error {
return nil
}
// 删除缓存
// 删除缓存-支持批量删除
func (c CacheUtil) RemoveCache(key interface{}) bool {
var cacheKey string
var cacheKey []string
switch k := key.(type) {
case int:
cacheKey = strconv.Itoa(k)
cacheKey = append(cacheKey, strconv.Itoa(k))
case string:
cacheKey = append(cacheKey, k)
// 判断是slice
case []int:
for _, v := range k {
cacheKey = append(cacheKey, strconv.Itoa(v))
}
case []string:
cacheKey = k
default:
return false
}
return RedisUtil.HDel(c.Name, cacheKey)
return RedisUtil.HDel(c.Name, cacheKey...)
}