local cache

This commit is contained in:
withchao 2024-01-10 16:24:46 +08:00
parent 8ff8861603
commit 006e4a1e93
5 changed files with 10 additions and 16 deletions

View File

@ -527,3 +527,9 @@ prometheus:
rtcPrometheusPort: [ ${RTC_PROM_PORT} ]
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
messageTransferPrometheusPort: [ ${MSG_TRANSFER_PROM_PORT} ] # List of ports
localCache:
friend:
topic: friend
slotNum: 500
slotSize: 20000

View File

@ -16,8 +16,6 @@ package friend
import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/OpenIMSDK/tools/tx"
"github.com/OpenIMSDK/protocol/sdkws"
@ -55,11 +53,6 @@ type friendServer struct {
}
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
config.Config.LocalCache.Friend.Topic = "friend"
config.Config.LocalCache.Friend.SlotNum = 500
config.Config.LocalCache.Friend.SlotSize = 20000
// Initialize MongoDB
mongo, err := unrelation.NewMongo()
if err != nil {

View File

@ -16,7 +16,6 @@ package msg
import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/rpccache"
"google.golang.org/grpc"
@ -66,11 +65,6 @@ func (m *msgServer) execInterceptorHandler(ctx context.Context, req *msg.SendMsg
}
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
config.Config.LocalCache.Friend.Topic = "friend"
config.Config.LocalCache.Friend.SlotNum = 500
config.Config.LocalCache.Friend.SlotSize = 20000
rdb, err := cache.NewRedis()
if err != nil {
return err

View File

@ -11,5 +11,5 @@ func GetBlackIDsKey(ownerUserID string) string {
}
func GetIsBlackIDsKey(possibleBlackUserID, userID string) string {
return isBlackKey + possibleBlackUserID + "-" + userID
return isBlackKey + userID + "-" + possibleBlackUserID
}

View File

@ -50,9 +50,10 @@ func (f *FriendLocalCache) IsFriend(ctx context.Context, possibleFriendUserID, u
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsFriendKey(possibleFriendUserID, userID), func(ctx context.Context) (any, error) {
log.ZDebug(ctx, "FriendLocalCache IsFriend rpc", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
return f.client.IsFriend(ctx, possibleFriendUserID, userID)
}, option.NewOption().WithLink(cachekey.GetFriendIDsKey(possibleFriendUserID), cachekey.GetFriendIDsKey(userID))))
}, option.NewOption().WithLink(cachekey.GetFriendIDsKey(possibleFriendUserID))))
}
// IsBlack possibleBlackUserID selfUserID
func (f *FriendLocalCache) IsBlack(ctx context.Context, possibleBlackUserID, userID string) (val bool, err error) {
log.ZDebug(ctx, "FriendLocalCache IsBlack req", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
defer func() {
@ -65,5 +66,5 @@ func (f *FriendLocalCache) IsBlack(ctx context.Context, possibleBlackUserID, use
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsBlackIDsKey(possibleBlackUserID, userID), func(ctx context.Context) (any, error) {
log.ZDebug(ctx, "FriendLocalCache IsBlack rpc", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
return f.client.IsBlack(ctx, possibleBlackUserID, userID)
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(possibleBlackUserID), cachekey.GetBlackIDsKey(userID))))
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(userID))))
}