refactor(controller): 优化Redis去重和缓存删除逻辑
This commit is contained in:
@@ -5,9 +5,9 @@ import (
|
||||
"dypid/global"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func ListTokenHandler(c *gin.Context) {
|
||||
@@ -146,17 +146,29 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
|
||||
global.RDB.Del(global.RCtx, keys...)
|
||||
default:
|
||||
//TODO 不考虑单独删除指定数量去重参考值
|
||||
_, err := strconv.Atoi(input.DedupBF)
|
||||
i, err := strconv.Atoi(input.DedupBF)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, 1, int64(i)).Val()
|
||||
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||
for _, s := range result {
|
||||
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, int64(i), -1)
|
||||
}
|
||||
switch input.CacheList {
|
||||
case "":
|
||||
case "all":
|
||||
global.RDB.Del(global.RCtx, "list:"+input.Token)
|
||||
global.RDB.Del(global.RCtx, "delete-list:"+input.Token)
|
||||
default:
|
||||
i, err := strconv.Atoi(input.CacheList)
|
||||
if err != nil {
|
||||
@@ -174,13 +186,19 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "both_number设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
result := global.RDB.LRange(global.RCtx, "list:"+input.Token, 1, int64(i)).Val()
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i))
|
||||
dataIndex, err := getDataIndex(input.Token)
|
||||
for _, s := range result {
|
||||
s2 := strings.Split(s, "----")[dataIndex[dedupObject]]
|
||||
global.RDB.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s2)
|
||||
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, 1, int64(i)).Val()
|
||||
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
|
||||
for _, s := range result {
|
||||
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, int64(i), -1)
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, int64(i), -1)
|
||||
}
|
||||
|
||||
//输出信息
|
||||
|
Reference in New Issue
Block a user