Files
open-im-server/pkg/common/db/cache/rockscache.go
T

71 lines
2.0 KiB
Go
Raw Normal View History

2023-01-16 20:14:26 +08:00
package cache
2022-07-14 12:08:28 +08:00
import (
2022-07-29 14:36:07 +08:00
"Open_IM/pkg/common/constant"
2023-01-31 18:55:22 +08:00
"Open_IM/pkg/common/db/relation"
2022-07-26 15:16:46 +08:00
"Open_IM/pkg/common/log"
2023-01-30 11:14:18 +08:00
"Open_IM/pkg/common/tracelog"
2022-07-20 15:49:21 +08:00
"Open_IM/pkg/utils"
2022-07-20 11:35:19 +08:00
"context"
2022-07-14 12:08:28 +08:00
"encoding/json"
2022-08-08 11:30:10 +08:00
"math/big"
"sort"
"strconv"
2022-07-14 12:08:28 +08:00
"time"
)
const (
2023-01-31 18:55:22 +08:00
//userInfoCache = "USER_INFO_CACHE:"
2023-02-01 11:23:01 +08:00
//friendRelationCache = "FRIEND_RELATION_CACHE:"
blackListCache = "BLACK_LIST_CACHE:"
2023-01-31 18:55:22 +08:00
//groupCache = "GROUP_CACHE:"
2023-01-17 16:36:34 +08:00
//groupInfoCache = "GROUP_INFO_CACHE:"
2023-01-31 18:55:22 +08:00
//groupOwnerIDCache = "GROUP_OWNER_ID:"
//joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:"
//groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:"
//groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:"
2023-02-01 11:23:01 +08:00
//allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:"
2023-01-31 18:55:22 +08:00
//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:"
2022-07-14 12:08:28 +08:00
)
2023-01-16 20:14:26 +08:00
const scanCount = 3000
2023-01-17 16:36:34 +08:00
const RandomExpireAdjustment = 0.2
2023-01-16 20:14:26 +08:00
func (rc *RcClient) DelKeys() {
2023-01-31 18:55:22 +08:00
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:"} {
2022-07-26 15:16:46 +08:00
fName := utils.GetSelfFuncName()
2022-07-20 11:35:19 +08:00
var cursor uint64
var n int
for {
var keys []string
var err error
2023-01-16 20:14:26 +08:00
keys, cursor, err = rc.rdb.Scan(context.Background(), cursor, key+"*", scanCount).Result()
2022-07-20 11:35:19 +08:00
if err != nil {
panic(err.Error())
}
n += len(keys)
2022-07-29 14:36:07 +08:00
// for each for redis cluster
2022-07-26 15:16:46 +08:00
for _, key := range keys {
2023-01-16 20:14:26 +08:00
if err = rc.rdb.Del(context.Background(), key).Err(); err != nil {
2022-07-26 15:16:46 +08:00
log.NewError("", fName, key, err.Error())
2023-01-16 20:14:26 +08:00
err = rc.rdb.Del(context.Background(), key).Err()
2022-07-26 15:16:46 +08:00
if err != nil {
panic(err.Error())
}
2022-07-20 12:08:58 +08:00
}
2022-07-20 12:05:57 +08:00
}
2022-07-20 11:35:19 +08:00
if cursor == 0 {
break
}
}
}
}