处理聊天缓存key代码
This commit is contained in:
parent
f9ae32a5f2
commit
84cd9d2a41
@ -8,6 +8,7 @@ import (
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -75,19 +76,19 @@ func (this *modelChatComp) getChatQueue(channel pb.ChatChannel, stag, union stri
|
||||
switch channel {
|
||||
case pb.ChatChannel_World:
|
||||
// key = worldchatkey
|
||||
key = fmt.Sprintf("%s-%s", worldchatkey, stag)
|
||||
key = fmt.Sprintf("%s-%s-%s", db.CrossTag(), worldchatkey, stag)
|
||||
find = bson.M{"channel": channel}
|
||||
break
|
||||
case pb.ChatChannel_Union:
|
||||
key = fmt.Sprintf("%s-%s", unionchatkey, union)
|
||||
key = fmt.Sprintf("%s-%s-%s", db.CrossTag(), unionchatkey, union)
|
||||
find = bson.M{"channel": channel, "unionId": union}
|
||||
break
|
||||
case pb.ChatChannel_CrossServer:
|
||||
key = fmt.Sprintf("%s-%d", crosschatkey, area)
|
||||
key = fmt.Sprintf("%s-%s-%d", db.CrossTag(), crosschatkey, area)
|
||||
find = bson.M{"channel": channel, "areaId": area}
|
||||
break
|
||||
case pb.ChatChannel_System:
|
||||
key = systemchatkey
|
||||
key = fmt.Sprintf("%s-%s", db.CrossTag(), systemchatkey)
|
||||
find = bson.M{"channel": channel}
|
||||
break
|
||||
}
|
||||
@ -141,7 +142,7 @@ func (this *modelChatComp) addCrossChannelMember(session comm.IUserSession) (cha
|
||||
return
|
||||
}
|
||||
for {
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||
key := fmt.Sprintf("%s-%s-%d-member", db.CrossTag(), crosschatkey, channel)
|
||||
if count, err = this.Redis.Hlen(key); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
@ -171,7 +172,7 @@ func (this *modelChatComp) chanageChannel(session comm.IUserSession, channel int
|
||||
var (
|
||||
maxnum int32
|
||||
)
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||
key := fmt.Sprintf("%s-%s-%d-member", db.CrossTag(), crosschatkey, channel)
|
||||
count := 0
|
||||
if maxnum, err = this.module.configure.GetChanageChannelMax(); err != nil {
|
||||
return
|
||||
@ -192,7 +193,7 @@ func (this *modelChatComp) chanageChannel(session comm.IUserSession, channel int
|
||||
|
||||
// 读取跨服聊天频道下成员
|
||||
func (this *modelChatComp) getCrossChannelMember(channel int32) (result []*pb.CacheUser, err error) {
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||
key := fmt.Sprintf("%s-%s-%d-member", db.CrossTag(), crosschatkey, channel)
|
||||
temp := make(map[string]*pb.CacheUser, 0)
|
||||
if err = this.Redis.HGetAll(key, &temp); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
@ -217,7 +218,7 @@ func (this *modelChatComp) removeCrossChannelMember(uid string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, result.Chatchannel)
|
||||
key := fmt.Sprintf("%s-%s-%d-member", db.CrossTag(), crosschatkey, result.Chatchannel)
|
||||
if err = this.Redis.HDel(key, uid); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
@ -322,7 +323,7 @@ func (this *modelChatComp) addChatMsg(key string, count int64, msgs ...*pb.DBCha
|
||||
|
||||
// 发送聊天消息到世界频道
|
||||
func (this *modelChatComp) sendChatToWorld(chat *pb.DBChat, queuecount int32) (err error) {
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, chat.Stag), int64(queuecount), chat); err != nil {
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s-%s", db.CrossTag(), worldchatkey, chat.Stag), int64(queuecount), chat); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -338,7 +339,7 @@ func (this *modelChatComp) sendChatToUnion(chat *pb.DBChat, queuecount int32) (e
|
||||
var (
|
||||
err error
|
||||
)
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", unionchatkey, chat.UnionId), int64(queuecount), chat); err != nil {
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s-%s", db.CrossTag(), unionchatkey, chat.UnionId), int64(queuecount), chat); err != nil {
|
||||
this.module.Errorln(err)
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
@ -356,7 +357,7 @@ func (this *modelChatComp) sendChatToUnion(chat *pb.DBChat, queuecount int32) (e
|
||||
|
||||
// 发送聊天消息到工会频道
|
||||
func (this *modelChatComp) sendChatToCrossServer(chat *pb.DBChat, queuecount int32) (err error) {
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, chat.ChannelId), int64(queuecount), chat); err != nil {
|
||||
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s-%d", db.CrossTag(), crosschatkey, chat.ChannelId), int64(queuecount), chat); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user