You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/db/cache/rockscache.go

71 lines
2.0 KiB

2 years ago
package cache
2 years ago
import (
"Open_IM/pkg/common/constant"
2 years ago
"Open_IM/pkg/common/db/relation"
2 years ago
"Open_IM/pkg/common/log"
2 years ago
"Open_IM/pkg/common/tracelog"
"Open_IM/pkg/utils"
"context"
2 years ago
"encoding/json"
2 years ago
"math/big"
"sort"
"strconv"
2 years ago
"time"
)
const (
2 years ago
//userInfoCache = "USER_INFO_CACHE:"
2 years ago
//friendRelationCache = "FRIEND_RELATION_CACHE:"
blackListCache = "BLACK_LIST_CACHE:"
2 years ago
//groupCache = "GROUP_CACHE:"
2 years ago
//groupInfoCache = "GROUP_INFO_CACHE:"
2 years ago
//groupOwnerIDCache = "GROUP_OWNER_ID:"
//joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
//groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
//groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
2 years ago
//allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
2 years ago
//joinedSuperGroupListCache = "JOINED_SUPER_GROUP_LIST_CACHE:"
//groupMemberListHashCache = "GROUP_MEMBER_LIST_HASH_CACHE:"
//groupMemberNumCache = "GROUP_MEMBER_NUM_CACHE:"
conversationCache = "CONVERSATION_CACHE:"
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
extendMsgSetCache = "EXTEND_MSG_SET_CACHE:"
extendMsgCache = "EXTEND_MSG_CACHE:"
2 years ago
)
2 years ago
const scanCount = 3000
2 years ago
const RandomExpireAdjustment = 0.2
2 years ago
func (rc *RcClient) DelKeys() {
2 years ago
for _, key := range []string{"GROUP_CACHE:", "FRIEND_RELATION_CACHE", "BLACK_LIST_CACHE:", "USER_INFO_CACHE:", "GROUP_INFO_CACHE", groupOwnerIDCache, joinedGroupListCache,
groupMemberInfoCache, groupAllMemberInfoCache, "ALL_FRIEND_INFO_CACHE:"} {
2 years ago
fName := utils.GetSelfFuncName()
var cursor uint64
var n int
for {
var keys []string
var err error
2 years ago
keys, cursor, err = rc.rdb.Scan(context.Background(), cursor, key+"*", scanCount).Result()
if err != nil {
panic(err.Error())
}
n += len(keys)
// for each for redis cluster
2 years ago
for _, key := range keys {
2 years ago
if err = rc.rdb.Del(context.Background(), key).Err(); err != nil {
2 years ago
log.NewError("", fName, key, err.Error())
2 years ago
err = rc.rdb.Del(context.Background(), key).Err()
2 years ago
if err != nil {
panic(err.Error())
}
}
}
if cursor == 0 {
break
}
}
}
}