上传用户缓存锁

This commit is contained in:
liwei1dao 2024-01-11 19:05:21 +08:00
parent bea34c2b0e
commit b6d15f2b60

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"go_dreamfactory/pb"
"sync"
"go_dreamfactory/lego/sys/log"
@ -31,6 +32,7 @@ type UserSession struct {
UserId string
service IService
msgqueue []*pb.UserMessage
lock sync.RWMutex
mate map[string]interface{}
}
@ -117,12 +119,16 @@ func (this *UserSession) UnBind() (err error) {
//写入元数据
func (this *UserSession) SetMate(name string, value interface{}) {
this.lock.Lock()
this.mate[name] = value
this.lock.Unlock()
}
//写入元数据
func (this *UserSession) GetMate(name string) (ok bool, value interface{}) {
this.lock.RLock()
value, ok = this.mate[name]
this.lock.RUnlock()
return
}
@ -189,9 +195,11 @@ func (this *UserSession) SyncPush() (err error) {
func (this *UserSession) Clone() (session IUserSession) {
session = this.service.GetUserSession()
session.SetSession(this.IP, this.SessionId, this.ServiceTag, this.GatewayServiceId, this.UserId)
this.lock.RLock()
for k, v := range this.mate {
session.SetMate(k, v)
}
this.lock.RUnlock()
return
}