mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
local cache
This commit is contained in:
parent
8ff8861603
commit
006e4a1e93
@ -527,3 +527,9 @@ prometheus:
|
|||||||
rtcPrometheusPort: [ ${RTC_PROM_PORT} ]
|
rtcPrometheusPort: [ ${RTC_PROM_PORT} ]
|
||||||
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
|
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
|
||||||
messageTransferPrometheusPort: [ ${MSG_TRANSFER_PROM_PORT} ] # List of ports
|
messageTransferPrometheusPort: [ ${MSG_TRANSFER_PROM_PORT} ] # List of ports
|
||||||
|
|
||||||
|
localCache:
|
||||||
|
friend:
|
||||||
|
topic: friend
|
||||||
|
slotNum: 500
|
||||||
|
slotSize: 20000
|
@ -16,8 +16,6 @@ package friend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/tx"
|
"github.com/OpenIMSDK/tools/tx"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/sdkws"
|
"github.com/OpenIMSDK/protocol/sdkws"
|
||||||
@ -55,11 +53,6 @@ type friendServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
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
|
// Initialize MongoDB
|
||||||
mongo, err := unrelation.NewMongo()
|
mongo, err := unrelation.NewMongo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,7 +16,6 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/rpccache"
|
"github.com/openimsdk/open-im-server/v3/pkg/rpccache"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"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 {
|
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()
|
rdb, err := cache.NewRedis()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -11,5 +11,5 @@ func GetBlackIDsKey(ownerUserID string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetIsBlackIDsKey(possibleBlackUserID, userID string) string {
|
func GetIsBlackIDsKey(possibleBlackUserID, userID string) string {
|
||||||
return isBlackKey + possibleBlackUserID + "-" + userID
|
return isBlackKey + userID + "-" + possibleBlackUserID
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
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)
|
log.ZDebug(ctx, "FriendLocalCache IsFriend rpc", "possibleFriendUserID", possibleFriendUserID, "userID", userID)
|
||||||
return f.client.IsFriend(ctx, possibleFriendUserID, 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) {
|
func (f *FriendLocalCache) IsBlack(ctx context.Context, possibleBlackUserID, userID string) (val bool, err error) {
|
||||||
log.ZDebug(ctx, "FriendLocalCache IsBlack req", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
log.ZDebug(ctx, "FriendLocalCache IsBlack req", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
||||||
defer func() {
|
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) {
|
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)
|
log.ZDebug(ctx, "FriendLocalCache IsBlack rpc", "possibleBlackUserID", possibleBlackUserID, "userID", userID)
|
||||||
return f.client.IsBlack(ctx, possibleBlackUserID, userID)
|
return f.client.IsBlack(ctx, possibleBlackUserID, userID)
|
||||||
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(possibleBlackUserID), cachekey.GetBlackIDsKey(userID))))
|
}, option.NewOption().WithLink(cachekey.GetBlackIDsKey(userID))))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user