批量删除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

@@ -10,8 +10,8 @@
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
<el-form-item label="项目uuid" prop="ProjectKey">
<el-input v-model="formData.ProjectKey" placeholder="请输入项目uuid" />
<el-form-item label="项目uuid" prop="ProjectKey" v-if="mode === 'edit'">
{{ formData.ProjectKey }}
</el-form-item>
<el-form-item label="项目名称" prop="ProjectName">
<el-input v-model="formData.ProjectName" placeholder="请输入项目名称" />

View File

@@ -200,9 +200,7 @@ func (service {{{ toCamelCase .EntityName }}}Service) DelBatch(Ids []string) (e
return err
}
//
for _, v := range Ids {
cacheUtil.RemoveCache(v)
}
cacheUtil.RemoveCache(Ids)
return nil
}

View File

@@ -239,9 +239,7 @@ func (service monitorClientService) DelBatch(Ids []string) (e error) {
return err
}
// 删除缓存
for _, v := range Ids {
cacheUtil.RemoveCache(v)
}
cacheUtil.RemoveCache(Ids)
return nil
}

View File

@@ -203,9 +203,7 @@ func (service monitorErrorService) DelBatch(Ids []string) (e error) {
return err
}
// 删除缓存
for _, v := range Ids {
cacheUtil.RemoveCache(v)
}
cacheUtil.RemoveCache(Ids)
return nil
}

View File

@@ -188,9 +188,10 @@ func (service monitorProjectService) DelBatch(Ids []string) (e error) {
return err
}
// 删除缓存
for _, v := range Ids {
cacheUtil.RemoveCache(v)
}
// for _, v := range Ids {
// cacheUtil.RemoveCache(v)
// }
cacheUtil.RemoveCache(Ids)
return nil
}

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...)
}