上传redis 改造
This commit is contained in:
parent
bfcec3f226
commit
07e6965aeb
@ -71,7 +71,7 @@ func (this *modelRank) queryRankUser() (ranks []string, err error) {
|
||||
var (
|
||||
result []string
|
||||
)
|
||||
if result, err = this.DBModel.Redis.ZRevRange(this.TableName, 0, 50).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), 0, 50).Result(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (this *modelRank) raceSettlement() {
|
||||
return
|
||||
}
|
||||
for _, v := range reward.GetDataList() {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(this.TableName, int64(v.RankLow-1), int64(v.RankUp)).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), int64(v.RankLow-1), int64(v.RankUp)).Result(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (this *modelBattleComp) queryrecord(oid string) (record *pb.DBBattleRecord,
|
||||
}
|
||||
|
||||
// 创建pve 战斗记录
|
||||
func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleEVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
func (this *modelBattleComp) createeve(session comm.IUserSession, stag string, conn *db.DBConn, btype pb.BattleType, req *pb.BattleEVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
record = &pb.DBBattleRecord{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Title: req.Title,
|
||||
@ -76,7 +76,7 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon
|
||||
return
|
||||
}
|
||||
if req.Format != nil {
|
||||
model := db.NewDBModel(comm.TableHero, conn)
|
||||
model := db.NewDBModel(stag, comm.TableHero, conn)
|
||||
record.Redflist = make([]*pb.DBBattleFormt, 1)
|
||||
record.Redflist[0] = &pb.DBBattleFormt{
|
||||
Leadpos: req.Format.Leadpos,
|
||||
@ -193,7 +193,7 @@ func (this *modelBattleComp) createeve(session comm.IUserSession, conn *db.DBCon
|
||||
}
|
||||
|
||||
// 创建pve 战斗记录
|
||||
func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
func (this *modelBattleComp) createpve(session comm.IUserSession, stag string, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
var (
|
||||
heros []*pb.DBHero = make([]*pb.DBHero, 5)
|
||||
captain int32
|
||||
@ -217,7 +217,7 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon
|
||||
Leadpos: req.Format.Leadpos,
|
||||
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
||||
}
|
||||
model := db.NewDBModel(comm.TableHero, conn)
|
||||
model := db.NewDBModel(stag, comm.TableHero, conn)
|
||||
if user, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
@ -333,7 +333,7 @@ func (this *modelBattleComp) createpve(session comm.IUserSession, conn *db.DBCon
|
||||
}
|
||||
|
||||
// 创建pve 战斗记录
|
||||
func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVBReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
func (this *modelBattleComp) createpvb(session comm.IUserSession, stag string, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVBReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
var (
|
||||
// buff *cfg.GamePandamasBuffData
|
||||
user *pb.DBUserExpand
|
||||
@ -365,7 +365,7 @@ func (this *modelBattleComp) createpvb(session comm.IUserSession, conn *db.DBCon
|
||||
Leadpos: v.Leadpos,
|
||||
Team: make([]*pb.BattleRole, len(v.Format)),
|
||||
}
|
||||
model := db.NewDBModel(comm.TableHero, conn)
|
||||
model := db.NewDBModel(stag, comm.TableHero, conn)
|
||||
//自己的英雄阵营
|
||||
for i, v := range v.Format {
|
||||
if v != "" {
|
||||
@ -603,7 +603,7 @@ func (this *modelBattleComp) creatertpvp(redmodel, bluemodel *db.DBModel, btype
|
||||
}
|
||||
|
||||
// 创建pve 战斗记录
|
||||
func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleLPVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
func (this *modelBattleComp) createlpve(session comm.IUserSession, stag string, conn *db.DBConn, btype pb.BattleType, req *pb.BattleLPVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
var (
|
||||
heros []*pb.DBHero = make([]*pb.DBHero, 5)
|
||||
user *pb.DBUserExpand
|
||||
@ -624,7 +624,7 @@ func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBCo
|
||||
Leadpos: req.Format.Leadpos,
|
||||
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
||||
}
|
||||
model := db.NewDBModel(comm.TableHero, conn)
|
||||
model := db.NewDBModel(stag, comm.TableHero, conn)
|
||||
if user, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
@ -1161,7 +1161,7 @@ func (this *modelBattleComp) creatStoneBattle(session comm.IUserSession, stoneBa
|
||||
}
|
||||
|
||||
// 创建pve 战斗记录
|
||||
func (this *modelBattleComp) createAddDebuffPve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq, conf *cfg.GameBattleReadyData, dibuff []int32) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
func (this *modelBattleComp) createAddDebuffPve(session comm.IUserSession, stag string, conn *db.DBConn, btype pb.BattleType, req *pb.BattlePVEReq, conf *cfg.GameBattleReadyData, dibuff []int32) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
|
||||
var (
|
||||
heros []*pb.DBHero = make([]*pb.DBHero, 5)
|
||||
captain int32
|
||||
@ -1185,7 +1185,7 @@ func (this *modelBattleComp) createAddDebuffPve(session comm.IUserSession, conn
|
||||
Leadpos: req.Format.Leadpos,
|
||||
Team: make([]*pb.BattleRole, len(req.Format.Format)),
|
||||
}
|
||||
model := db.NewDBModel(comm.TableHero, conn)
|
||||
model := db.NewDBModel(comm.TableHero, stag, conn)
|
||||
if user, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
|
@ -101,12 +101,15 @@ func (this *Battle) CreateEveBattle(session comm.IUserSession, req *pb.BattleEVE
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
stag string
|
||||
err error
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
stag = this.service.GetTag()
|
||||
} else {
|
||||
conn, err = db.ServerDBConn(session.GetServiecTag())
|
||||
stag = session.GetServiecTag()
|
||||
}
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -127,7 +130,7 @@ func (this *Battle) CreateEveBattle(session comm.IUserSession, req *pb.BattleEVE
|
||||
return
|
||||
}
|
||||
|
||||
if record, errdata = this.modelBattle.createeve(session, conn, pb.BattleType_eve, req, conf); errdata != nil {
|
||||
if record, errdata = this.modelBattle.createeve(session, stag, conn, pb.BattleType_eve, req, conf); errdata != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
@ -138,13 +141,17 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
stag string
|
||||
err error
|
||||
tasks []*pb.BuriedParam
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
stag = this.service.GetTag()
|
||||
} else {
|
||||
|
||||
conn, err = db.ServerDBConn(session.GetServiecTag())
|
||||
stag = session.GetServiecTag()
|
||||
}
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -186,7 +193,7 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE
|
||||
}
|
||||
}
|
||||
|
||||
if record, errdata = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req, conf); errdata != nil {
|
||||
if record, errdata = this.modelBattle.createpve(session, stag, conn, pb.BattleType_pve, req, conf); errdata != nil {
|
||||
return
|
||||
}
|
||||
if flag {
|
||||
@ -207,7 +214,8 @@ func (this *Battle) CreateHeroPveBattle(session comm.IUserSession, req *pb.Battl
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
err error
|
||||
|
||||
err error
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
@ -251,12 +259,15 @@ func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVB
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
stag string
|
||||
err error
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
stag = this.service.GetTag()
|
||||
} else {
|
||||
conn, err = db.ServerDBConn(session.GetServiecTag())
|
||||
stag = session.GetServiecTag()
|
||||
}
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -282,7 +293,7 @@ func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVB
|
||||
}
|
||||
return
|
||||
}
|
||||
if record, errdata = this.modelBattle.createpvb(session, conn, pb.BattleType_pvb, req, conf); errdata != nil {
|
||||
if record, errdata = this.modelBattle.createpvb(session, stag, conn, pb.BattleType_pvb, req, conf); errdata != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
@ -373,13 +384,16 @@ func (this *Battle) CreateLPVEBattle(session comm.IUserSession, req *pb.BattleLP
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
stag string
|
||||
err error
|
||||
tasks []*pb.BuriedParam
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
stag = this.service.GetTag()
|
||||
} else {
|
||||
conn, err = db.ServerDBConn(session.GetServiecTag())
|
||||
stag = session.GetServiecTag()
|
||||
}
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -420,7 +434,7 @@ func (this *Battle) CreateLPVEBattle(session comm.IUserSession, req *pb.BattleLP
|
||||
}
|
||||
return
|
||||
}
|
||||
if record, errdata = this.modelBattle.createlpve(session, conn, pb.BattleType_lpev, req, conf); errdata != nil {
|
||||
if record, errdata = this.modelBattle.createlpve(session, stag, conn, pb.BattleType_lpev, req, conf); errdata != nil {
|
||||
return
|
||||
}
|
||||
if flag {
|
||||
@ -610,13 +624,16 @@ func (this *Battle) CreateDebuffBattle(session comm.IUserSession, req *pb.Battle
|
||||
var (
|
||||
conf *cfg.GameBattleReadyData
|
||||
conn *db.DBConn
|
||||
stag string
|
||||
err error
|
||||
tasks []*pb.BuriedParam
|
||||
)
|
||||
if !this.IsCross() {
|
||||
conn, err = db.Local()
|
||||
stag = this.service.GetTag()
|
||||
} else {
|
||||
conn, err = db.ServerDBConn(session.GetServiecTag())
|
||||
stag = session.GetServiecTag()
|
||||
}
|
||||
if err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -658,7 +675,7 @@ func (this *Battle) CreateDebuffBattle(session comm.IUserSession, req *pb.Battle
|
||||
}
|
||||
}
|
||||
|
||||
if record, errdata = this.modelBattle.createAddDebuffPve(session, conn, pb.BattleType_pve, req, conf, dibuff); errdata != nil {
|
||||
if record, errdata = this.modelBattle.createAddDebuffPve(session, stag, conn, pb.BattleType_pve, req, conf, dibuff); errdata != nil {
|
||||
return
|
||||
}
|
||||
if flag {
|
||||
|
@ -59,7 +59,7 @@ func (this *modelBuried) updateUserBurieds(uid string, data *pb.DBBuried) (err e
|
||||
}
|
||||
|
||||
func (this *modelBuried) userlock(uid string) (result *redis.RedisMutex, err error) {
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("ulockburied:%s", uid))
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("%s-ulockburied:%s", this.DBModel.ServiceId, uid))
|
||||
}
|
||||
|
||||
// 更新埋点数据到db中
|
||||
@ -110,7 +110,7 @@ func (this *buriedModel) updateUserBurieds(uid string, data *pb.DBBuried) (err e
|
||||
}
|
||||
|
||||
func (this *buriedModel) userlock(uid string) (result *redis.RedisMutex, err error) {
|
||||
return this.model.Redis.NewRedisMutex(fmt.Sprintf("ulockburied:%s", uid))
|
||||
return this.model.Redis.NewRedisMutex(fmt.Sprintf("%s-ulockburied:%s", this.model.ServiceId, uid))
|
||||
}
|
||||
|
||||
//获取埋点数据
|
||||
|
@ -46,7 +46,7 @@ func (this *ModelRank) SetUsrRankList(uid string) (result *pb.DBCaravanRank, err
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if model = db.NewDBModelByExpired(comm.TableCaravanRank, conn_); model == nil {
|
||||
if model = db.NewDBModelByExpired(db.CrossTag(), comm.TableCaravanRank, conn_); model == nil {
|
||||
err = fmt.Errorf("cand found table :%s,%v", comm.TableCaravanRank, conn_)
|
||||
return
|
||||
}
|
||||
@ -85,7 +85,7 @@ func (this *ModelRank) ChangeRankList(uId string, data map[string]interface{}) (
|
||||
return
|
||||
}
|
||||
|
||||
model := db.NewDBModelByExpired(comm.TableCaravanRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableCaravanRank, conn_)
|
||||
if model == nil {
|
||||
return
|
||||
}
|
||||
@ -104,7 +104,7 @@ func (this *ModelRank) getRankList(uid string) (list []*pb.CaravanRankInfo, rank
|
||||
return
|
||||
}
|
||||
|
||||
model := db.NewDBModelByExpired(comm.TableCaravanRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableCaravanRank, conn_)
|
||||
if model == nil {
|
||||
return
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ func (this *Caravan) Rpc_ModuleCaravanSettlement(ctx context.Context, args *pb.E
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableCaravanRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableCaravanRank, conn_)
|
||||
if model == nil {
|
||||
return
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ DB组件也封装进来
|
||||
*/
|
||||
type MCompModel struct {
|
||||
cbase.ModuleCompBase
|
||||
service core.IService
|
||||
TableName string
|
||||
Expired time.Duration //过期时间
|
||||
Redis redis.ISys
|
||||
@ -35,6 +36,7 @@ func (this *MCompModel) Init(service core.IService, module core.IModule, comp co
|
||||
this.DB = conn.Mgo
|
||||
this.Redis = conn.Redis
|
||||
this.Expired = time.Hour
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
||||
@ -48,7 +50,7 @@ func (this *MCompModel) Start() (err error) {
|
||||
if conn, err = db.Local(); err != nil {
|
||||
return
|
||||
}
|
||||
this.DBModel = db.NewDBModel(this.TableName, conn)
|
||||
this.DBModel = db.NewDBModel(this.service.GetId(), this.TableName, conn)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ func (this *Dragon) QueryDragonByTagAndOid(tag string, objId []string) (dragon [
|
||||
return
|
||||
}
|
||||
dragon = make([]*pb.DBDragon, 0)
|
||||
model = db.NewDBModel(this.modelDragon.TableName, conn)
|
||||
model = db.NewDBModel(tag, this.modelDragon.TableName, conn)
|
||||
|
||||
result := make([]bson.M, 0)
|
||||
|
||||
|
@ -2,6 +2,7 @@ package enchant
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/pb"
|
||||
@ -27,12 +28,12 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.EnchantRankList
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
conn, _ := db.Local()
|
||||
dbModel := db.NewDBModelByExpired(comm.TableEnchantRank, conn)
|
||||
dbModel := db.NewDBModelByExpired(this.service.GetTag(), comm.TableEnchantRank, conn)
|
||||
if !req.Friend {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = this.module.modelEnchant.Redis.RedisPipe(context.TODO())
|
||||
)
|
||||
rd = pipe.ZRange("enchantRank"+strconv.Itoa(int(req.BoosType)), 0, comm.MaxRankList)
|
||||
rd = pipe.ZRange(fmt.Sprintf("%s-%s", this.module.modelEnchant.DBModel.ServiceId, "enchantRank"+strconv.Itoa(int(req.BoosType))), 0, comm.MaxRankList)
|
||||
|
||||
if _, err := pipe.Exec(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
|
@ -89,7 +89,7 @@ func (this *Enchant) CheckUserBaseEnchantInfo(uid string) (data []*pb.DBEnchantR
|
||||
func (this *Enchant) CheckRank(uid string, boosID int32, report *pb.BattleReport, userinfo *pb.DBUser, score int64) {
|
||||
conn_, _ := db.Cross() // 获取跨服数据库对象
|
||||
|
||||
model := db.NewDBModelByExpired(comm.TableEnchantRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableEnchantRank, conn_)
|
||||
|
||||
costTime := report.Costtime
|
||||
szLine := make([]*pb.LineUp, len(report.Info.Redflist[0].Team))
|
||||
|
@ -2,6 +2,7 @@ package entertainment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
@ -70,7 +71,7 @@ func (this *modelRank) queryRankUser() (ranks []string, err error) {
|
||||
var (
|
||||
result []string
|
||||
)
|
||||
if result, err = this.DBModel.Redis.ZRevRange(this.TableName, 0, 50).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), 0, 50).Result(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ func (this *Friend) UpdateUserBaseInfo(session comm.IUserSession, info *pb.BaseU
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if model = db.NewDBModelByExpired(comm.TableFriend, conn_); model == nil {
|
||||
if model = db.NewDBModelByExpired(db.CrossTag(), comm.TableFriend, conn_); model == nil {
|
||||
err = fmt.Errorf("cand found table :%s,%v", comm.TableFriend, conn_)
|
||||
return
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.GourmetGetRa
|
||||
tag, _, b := utils.UIdSplit(session.GetUserId())
|
||||
if b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableHero, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableHero, conn)
|
||||
if _data, err1 := dbModel.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil {
|
||||
for _data.Next(context.TODO()) {
|
||||
temp := &pb.DBUser{}
|
||||
|
@ -60,7 +60,7 @@ func (this *ModelUnionroulette) updateUnionRoulette(data *pb.DBGuildRouletteReco
|
||||
|
||||
// 分布式锁
|
||||
func (this *ModelUnionroulette) userlock(id string) (result *redis.RedisMutex, err error) {
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("lockunionroulette:%s", id))
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("%s-lockunionroulette:%s", this.DBModel.ServiceId, id))
|
||||
}
|
||||
|
||||
// boos 信息变化推送
|
||||
|
@ -181,7 +181,7 @@ func (this *ModelUniongve) refreshGlobalBoos() (conf *pb.DBGuildGveBossConf, err
|
||||
|
||||
// 分布式锁
|
||||
func (this *ModelUniongve) userlock(id string) (result *redis.RedisMutex, err error) {
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("lockuniongve:%s", id))
|
||||
return this.DBModel.Redis.NewRedisMutex(fmt.Sprintf("%s-lockuniongve:%s", this.DBModel.ServiceId, id))
|
||||
}
|
||||
|
||||
// boos 血量变化推送
|
||||
@ -294,7 +294,7 @@ func (this *ModelUniongve) guildgveModel() (model *guildgveModel, err error) {
|
||||
if conn, err = db.Cross(); err != nil {
|
||||
return
|
||||
}
|
||||
m = db.NewDBModel(this.TableName, conn)
|
||||
m = db.NewDBModel(db.CrossTag(), this.TableName, conn)
|
||||
model = &guildgveModel{module: this.module, model: m}
|
||||
}
|
||||
return
|
||||
@ -308,7 +308,7 @@ type guildgveModel struct {
|
||||
|
||||
// 分布式锁
|
||||
func (this *guildgveModel) userlock(id string) (result *redis.RedisMutex, err error) {
|
||||
return this.model.Redis.NewRedisMutex(fmt.Sprintf("lockuniongve:%s", id))
|
||||
return this.model.Redis.NewRedisMutex(fmt.Sprintf("%s-lockuniongve:%s", this.model.ServiceId, id))
|
||||
}
|
||||
|
||||
// 获取用户全部的埋点数据
|
||||
|
@ -31,7 +31,7 @@ func (this *Modelbattlerank) Start() (err error) {
|
||||
}
|
||||
|
||||
func (this *Modelbattlerank) key(boos int32) string {
|
||||
return fmt.Sprintf("%s:%d", this.TableName, boos)
|
||||
return fmt.Sprintf("%s-%s:%d", this.DBModel.ServiceId, this.TableName, boos)
|
||||
}
|
||||
|
||||
// 获取排行榜前50的用户名单
|
||||
|
@ -2,6 +2,7 @@ package guildgve
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
@ -105,7 +106,7 @@ func (this *modelRank) raceSettlement() {
|
||||
return
|
||||
}
|
||||
for _, v := range reward.GetDataList() {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(this.TableName, int64(v.RankLow-1), int64(v.RankUp)).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName), int64(v.RankLow-1), int64(v.RankUp)).Result(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -115,7 +116,7 @@ func (this *modelRank) raceSettlement() {
|
||||
}
|
||||
}
|
||||
//清理排行榜
|
||||
this.DBModel.Redis.Delete(this.TableName)
|
||||
this.DBModel.Redis.Delete(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName))
|
||||
}
|
||||
|
||||
// boos 奖励推送
|
||||
|
@ -36,7 +36,7 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.HeroInfoReq) (errda
|
||||
|
||||
if tag, _, ok := utils.UIdSplit(uid); ok {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableHero, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableHero, conn)
|
||||
for _, v := range req.HeroId {
|
||||
if v == "" {
|
||||
continue
|
||||
|
@ -93,11 +93,11 @@ func TimerStar() {
|
||||
if !db.IsCross() {
|
||||
conn, err := db.Cross()
|
||||
if err == nil {
|
||||
model := db.NewDBModel(comm.TablePagodaRecord, conn)
|
||||
model := db.NewDBModel(db.CrossTag(), comm.TablePagodaRecord, conn)
|
||||
//model.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete())
|
||||
model.DB.DeleteMany(comm.TablePagodaRecord, bson.M{}, options.Delete())
|
||||
for pos := 0; pos < comm.MaxRankNum; pos++ {
|
||||
key1 := fmt.Sprintf("pagodaList%d", pos)
|
||||
key1 := fmt.Sprintf("%s-pagodaList%d", db.CrossTag(), pos)
|
||||
if err := model.Redis.Delete(key1); err != nil {
|
||||
log.Errorf("delete failed")
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func (this *ModelRank) getHuntingRank(uid string) *pb.DBHuntingRecord {
|
||||
data := &pb.DBHuntingRecord{}
|
||||
if !db.IsCross() {
|
||||
if conn_, err := db.Cross(); err == nil {
|
||||
model := db.NewDBModelByExpired(comm.TableHuntingRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableHuntingRank, conn_)
|
||||
|
||||
if err := model.Get(uid, data); err != nil {
|
||||
return data
|
||||
@ -88,7 +88,7 @@ func (this *ModelRank) CheckRank(uid string, boosID int32, difficulty int32, lin
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableHuntingRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableHuntingRank, conn_)
|
||||
|
||||
// 写入排行榜
|
||||
record := &pb.DBHuntingRecord{
|
||||
|
@ -2,6 +2,7 @@ package integral
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
@ -56,7 +57,7 @@ func (this *modelRank) queryIntegralRankUser(nandu int) (ranks []string, err err
|
||||
var (
|
||||
result []string
|
||||
)
|
||||
if result, err = this.DBModel.Redis.ZRevRange(this.TableName+strconv.Itoa(nandu), 0, 50).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel.ServiceId, this.TableName+strconv.Itoa(nandu)), 0, 50).Result(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (this *Mail) SendNewMail(mail *pb.DBMailData, uid ...string) bool {
|
||||
tag, _, b := utils.UIdSplit(id)
|
||||
if b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableMail, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableMail, conn)
|
||||
mail.ObjId = primitive.NewObjectID().Hex()
|
||||
mail.Check = false
|
||||
mail.Reward = true
|
||||
@ -198,7 +198,7 @@ func (this *Mail) SendMailByCid(session comm.IUserSession, cid string, res []*pb
|
||||
tag, _, b := utils.UIdSplit(session.GetUserId())
|
||||
if b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableMail, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableMail, conn)
|
||||
|
||||
if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil {
|
||||
this.Errorf("InsertOne mail failed:%v", err)
|
||||
@ -275,7 +275,7 @@ func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Para
|
||||
tag, _, b := utils.UIdSplit(uid)
|
||||
if b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableMail, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableMail, conn)
|
||||
|
||||
if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil {
|
||||
this.Errorf("InsertOne mail failed:%v", err)
|
||||
@ -342,7 +342,7 @@ func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res
|
||||
tag, _, b := utils.UIdSplit(session.GetUserId())
|
||||
if b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableMail, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableMail, conn)
|
||||
|
||||
if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil {
|
||||
this.Errorf("InsertOne mail failed:%v", err)
|
||||
@ -399,7 +399,7 @@ func (this *Mail) SendMailToUsers(uids []string, cid string, res []*cfg.Gameatn,
|
||||
Cid: cid,
|
||||
Param: param,
|
||||
}
|
||||
dbModel := db.NewDBModel(comm.TableMail, conn)
|
||||
dbModel := db.NewDBModel(tag, comm.TableMail, conn)
|
||||
mail.ObjId = primitive.NewObjectID().Hex()
|
||||
mail.Check = false
|
||||
mail.Reward = true
|
||||
|
@ -603,7 +603,7 @@ func (this *ModuleBase) GetDBNodule(session comm.IUserSession, tableName string,
|
||||
return
|
||||
}
|
||||
}
|
||||
model = db.NewDBModel(tableName, conn)
|
||||
model = db.NewDBModel(this.service.GetId(), tableName, conn)
|
||||
return
|
||||
}
|
||||
|
||||
@ -621,7 +621,7 @@ func (this *ModuleBase) GetCrossDBModel(tableName string) (model *db.DBModel, er
|
||||
return
|
||||
}
|
||||
}
|
||||
model = db.NewDBModel(tableName, conn)
|
||||
model = db.NewDBModel(this.service.GetId(), tableName, conn)
|
||||
return
|
||||
}
|
||||
|
||||
@ -643,7 +643,7 @@ func (this *ModuleBase) GetDBModelByUid(uid, tableName string) (model *db.DBMode
|
||||
return
|
||||
}
|
||||
}
|
||||
model = db.NewDBModel(tableName, conn)
|
||||
model = db.NewDBModel(this.service.GetId(), tableName, conn)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
|
||||
// 数据写到跨服中
|
||||
if conn_, err := db.Cross(); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TablePagodaRecord, conn_)
|
||||
dbModel := db.NewDBModel(db.CrossTag(), comm.TablePagodaRecord, conn_)
|
||||
dbModel.AddList(session.GetUserId(), newData.Id, newData)
|
||||
} else {
|
||||
this.module.Errorf("db crosserr :%v", err)
|
||||
|
@ -2,6 +2,7 @@ package pagoda
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/pb"
|
||||
@ -37,10 +38,10 @@ func (this *apiComp) CrossRaceRankList(session comm.IUserSession, req *pb.Pagoda
|
||||
|
||||
if this.module.IsCross() {
|
||||
conn, _ := db.Local()
|
||||
dbModel := db.NewDBModel(comm.TableRaceRecord, conn)
|
||||
dbModel := db.NewDBModel(this.service.GetTag(), comm.TableRaceRecord, conn)
|
||||
|
||||
pipe = conn.Redis.RedisPipe(context.TODO())
|
||||
tablename := "race" + strconv.Itoa(int(req.Raceid))
|
||||
tablename := fmt.Sprintf("%s-%s", this.service.GetTag(), "race"+strconv.Itoa(int(req.Raceid)))
|
||||
rd = pipe.ZRevRange(tablename, 0, comm.MaxRankList)
|
||||
|
||||
if _, err := pipe.Exec(); err != nil {
|
||||
|
@ -155,7 +155,7 @@ func (this *apiComp) ChallengeRaceOver(session comm.IUserSession, req *pb.Pagoda
|
||||
|
||||
// 数据写到跨服中
|
||||
if conn_, err := db.Cross(); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableRaceRecord, conn_)
|
||||
dbModel := db.NewDBModel(db.CrossTag(), comm.TableRaceRecord, conn_)
|
||||
result := make([]*pb.DBRacePagodaRecord, 0)
|
||||
bRet := false
|
||||
dbModel.GetList(uid, &result)
|
||||
|
@ -43,7 +43,7 @@ func (this *ModelRank) getPagodaRankListByFloorid(uid string, cid int32) *pb.DBP
|
||||
}
|
||||
} else {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TablePagodaRecord, conn)
|
||||
dbModel := db.NewDBModel(db.CrossTag(), comm.TablePagodaRecord, conn)
|
||||
if err = dbModel.GetList(uid, &pagodaRank); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func (this *Practice) AddItems(session comm.IUserSession, items map[string]int32
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
model := db.NewDBModel(comm.TablePandata, conn)
|
||||
model := db.NewDBModel(db.CrossTag(), comm.TablePandata, conn)
|
||||
if err = model.Get(session.GetUserId(), room); err != nil && err != mgo.MongodbNil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
@ -405,7 +405,7 @@ func (this *Practice) RPC_ModulePracticeUnLockPillar(ctx context.Context, args *
|
||||
// 一键踢馆 (跨服)
|
||||
func (this *Practice) CleanUpNpc(uid string) {
|
||||
conn_, _ := db.Cross() // 获取跨服数据库对象
|
||||
model := db.NewDBModel(comm.TablePandata, conn_)
|
||||
model := db.NewDBModel(db.CrossTag(), comm.TablePandata, conn_)
|
||||
result := &pb.DBPracticeRoom{}
|
||||
if err := model.Get(uid, result); err != nil && err != mgo.MongodbNil {
|
||||
return
|
||||
|
@ -180,7 +180,7 @@ func (this *ModelSociaty) getSociaty(sociatyId string) (sociaty *pb.DBSociaty, e
|
||||
if conn, err = db.Cross(); err != nil {
|
||||
return
|
||||
}
|
||||
model = db.NewDBModel(this.TableName, conn)
|
||||
model = db.NewDBModel(db.CrossTag(), this.TableName, conn)
|
||||
if err = model.GetListObj(comm.RDS_EMPTY, sociatyId, sociaty); err != nil {
|
||||
this.module.Error("获取工会信息 失败", log.Field{Key: "sociatyId", Value: sociatyId}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
|
@ -374,9 +374,9 @@ func (this *Sociaty) RpcUpdateUserTask(ctx context.Context, p *TaskParams, reply
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableSociatyTask, conn)
|
||||
model := db.NewDBModel(this.service.GetTag(), comm.TableSociatyTask, conn)
|
||||
|
||||
if err := model.Redis.HMSet(fmt.Sprintf("%s:%s-%s", this.modelSociatyTask.TableName,
|
||||
if err := model.Redis.HMSet(fmt.Sprintf("%s-%s:%s-%s", model.ServiceId, this.modelSociatyTask.TableName,
|
||||
p.SociatyId, p.Uid), p.Data); err != nil {
|
||||
log.Error("DBModel ChangeList", log.Field{Key: "err", Value: err.Error()})
|
||||
return err
|
||||
|
@ -95,7 +95,7 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er
|
||||
return
|
||||
}
|
||||
}
|
||||
model = db.NewDBModel(tableName, conn)
|
||||
model = db.NewDBModel(stag, tableName, conn)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,37 +1,37 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
// import (
|
||||
// "go_dreamfactory/comm"
|
||||
// "go_dreamfactory/pb"
|
||||
// "go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
// "go.mongodb.org/mongo-driver/bson"
|
||||
// )
|
||||
|
||||
func (this *apiComp) GetServerDataCheck(session comm.IUserSession, req *pb.UserGetServerDataReq) (errdata *pb.ErrorData) {
|
||||
return
|
||||
}
|
||||
// func (this *apiComp) GetServerDataCheck(session comm.IUserSession, req *pb.UserGetServerDataReq) (errdata *pb.ErrorData) {
|
||||
// return
|
||||
// }
|
||||
|
||||
func (this *apiComp) GetServerData(session comm.IUserSession, req *pb.UserGetServerDataReq) (errdata *pb.ErrorData) {
|
||||
// func (this *apiComp) GetServerData(session comm.IUserSession, req *pb.UserGetServerDataReq) (errdata *pb.ErrorData) {
|
||||
|
||||
rsp := &pb.UserGetServerDataResp{
|
||||
Data: &pb.DBServerData{},
|
||||
}
|
||||
// rsp := &pb.UserGetServerDataResp{
|
||||
// Data: &pb.DBServerData{},
|
||||
// }
|
||||
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
dbModel := db.NewDBModel(comm.TableHero, conn)
|
||||
if _data := dbModel.DB.FindOne("serverdata", bson.M{}); _data != nil {
|
||||
_data.Decode(rsp.Data)
|
||||
} else {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
if err := session.SendMsg(string(this.module.GetType()), UserGetServerDataResp, rsp); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_SystemError,
|
||||
Title: pb.ErrorCode_SystemError.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
// if conn, err := db.Cross(); err == nil {
|
||||
// dbModel := db.NewDBModel(comm.TableHero, conn)
|
||||
// if _data := dbModel.DB.FindOne("serverdata", bson.M{}); _data != nil {
|
||||
// _data.Decode(rsp.Data)
|
||||
// } else {
|
||||
// this.module.Errorf("err:%v", err)
|
||||
// }
|
||||
// }
|
||||
// if err := session.SendMsg(string(this.module.GetType()), UserGetServerDataResp, rsp); err != nil {
|
||||
// errdata = &pb.ErrorData{
|
||||
// Code: pb.ErrorCode_SystemError,
|
||||
// Title: pb.ErrorCode_SystemError.ToString(),
|
||||
// Message: err.Error(),
|
||||
// }
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
@ -132,7 +132,7 @@ func (this *ModelUser) GetCrossUsers(uids []string) (users []*pb.DBUser, err err
|
||||
if conn, err = db.ServerDBConn(k); err != nil {
|
||||
return
|
||||
}
|
||||
model = db.NewDBModel(this.TableName, conn)
|
||||
model = db.NewDBModel(k, this.TableName, conn)
|
||||
usersSlice = make([]*pb.DBUser, 0)
|
||||
if _, err = model.Gets(v, &usersSlice); err != nil {
|
||||
return
|
||||
|
@ -227,7 +227,7 @@ func (this *User) CrossUserOnlineList() ([]*pb.CacheUser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableSession, conn)
|
||||
model := db.NewDBModelByExpired(this.service.GetTag(), comm.TableSession, conn)
|
||||
var cache []*pb.CacheUser
|
||||
if err := model.GetList(comm.RDS_EMPTY, &cache); err != nil {
|
||||
return nil, err
|
||||
@ -241,7 +241,7 @@ func (this *User) crossUser(uid string) (*pb.CacheUser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableSession, conn)
|
||||
model := db.NewDBModelByExpired(this.service.GetTag(), comm.TableSession, conn)
|
||||
cache := &pb.CacheUser{}
|
||||
if err := model.Get(uid, cache); err != nil {
|
||||
return nil, err
|
||||
@ -289,7 +289,7 @@ func (this *User) RpcCreateSociaty(ctx context.Context, req *pb.RPCGeneralReqA2,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableSociaty, conn)
|
||||
model := db.NewDBModel(this.service.GetTag(), comm.TableSociaty, conn)
|
||||
|
||||
sociaty := &pb.DBSociaty{}
|
||||
_id := primitive.NewObjectID().Hex()
|
||||
@ -948,7 +948,7 @@ func (this *User) getUserFromRemoteDb(uid string, rsp *pb.DBUser) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableUser, conn)
|
||||
model := db.NewDBModel(sid, comm.TableUser, conn)
|
||||
if err := model.Get(uid, rsp); err != nil {
|
||||
this.Errorln("Get User:", err)
|
||||
return err
|
||||
@ -965,7 +965,7 @@ func (this *User) getUserExpandFromRemoteDb(uid string, rsp *pb.DBUserExpand) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableUserExpand, conn)
|
||||
model := db.NewDBModel(sid, comm.TableUserExpand, conn)
|
||||
|
||||
if err := model.Get(uid, rsp); err != nil {
|
||||
return err
|
||||
@ -982,7 +982,7 @@ func (this *User) changeUserExpandFromRemoteDb(uid string, data map[string]inter
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModel(comm.TableUserExpand, conn)
|
||||
model := db.NewDBModel(sid, comm.TableUserExpand, conn)
|
||||
|
||||
if err := model.Change(uid, data); err != nil {
|
||||
return err
|
||||
@ -1021,7 +1021,7 @@ func (this *User) RpcGetAllOnlineUser(ctx context.Context, args *pb.EmptyReq, re
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableSession, conn)
|
||||
model := db.NewDBModelByExpired(this.service.GetTag(), comm.TableSession, conn)
|
||||
var cache []*pb.CacheUser
|
||||
if err := model.GetList(comm.RDS_EMPTY, &cache); err != nil {
|
||||
return err
|
||||
@ -1039,7 +1039,7 @@ func (this *User) RpcGetCrossUserSession(ctx context.Context, req *pb.UIdReq, re
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableSession, conn)
|
||||
model := db.NewDBModelByExpired(this.service.GetTag(), comm.TableSession, conn)
|
||||
if err := model.GetListObj(comm.RDS_EMPTY, req.Uid, reply); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
return err
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
@ -25,17 +24,12 @@ func (this *apiComp) SeasonRank(session comm.IUserSession, req *pb.VikingSeasonR
|
||||
err error
|
||||
ranks []*pb.DBVSeasonRecord
|
||||
players []*pb.DBVikingSRank
|
||||
conn_ *db.DBConn
|
||||
)
|
||||
if errdata = this.SeasonRankCheck(session, req); errdata != nil {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
|
||||
conn_, err = db.Cross()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if uids, err = this.module.modelsrank.querySRankUser(int(req.BoosType), conn_); err != nil {
|
||||
if uids, err = this.module.modelsrank.querySRankUser(int(req.BoosType)); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
@ -43,7 +37,7 @@ func (this *apiComp) SeasonRank(session comm.IUserSession, req *pb.VikingSeasonR
|
||||
}
|
||||
return
|
||||
}
|
||||
if ranks, err = this.module.modelsrank.queryPlayers(uids, conn_); err != nil {
|
||||
if ranks, err = this.module.modelsrank.queryPlayers(uids); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_DBError,
|
||||
Title: pb.ErrorCode_DBError.ToString(),
|
||||
|
@ -39,7 +39,7 @@ func (this *ModelRank) getVikingRank(uid string) *pb.DBVikingRecord {
|
||||
data := &pb.DBVikingRecord{}
|
||||
if !db.IsCross() {
|
||||
if conn_, err := db.Cross(); err == nil {
|
||||
model := db.NewDBModelByExpired(comm.TableVikingRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableVikingRank, conn_)
|
||||
|
||||
if err := model.Get(uid, data); err != nil {
|
||||
return data
|
||||
@ -88,7 +88,7 @@ func (this *ModelRank) CheckRank(uid string, boosID int32, difficulty int32, lin
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableVikingRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableVikingRank, conn_)
|
||||
|
||||
// 写入排行榜
|
||||
record := &pb.DBVikingRecord{
|
||||
|
@ -39,9 +39,14 @@ func (this *ModelSRank) Init(service core.IService, module core.IModule, comp co
|
||||
}
|
||||
|
||||
// 批量查询
|
||||
func (this *ModelSRank) queryPlayers(uIds []string, conn_ *db.DBConn) (result []*pb.DBVSeasonRecord, err error) {
|
||||
func (this *ModelSRank) queryPlayers(uIds []string) (result []*pb.DBVSeasonRecord, err error) {
|
||||
var conn *db.DBConn
|
||||
conn, err = db.Cross()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
result = make([]*pb.DBVSeasonRecord, 0)
|
||||
model := db.NewDBModelByExpired(comm.TableVikingSRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableVikingSRank, conn)
|
||||
if _, err = model.GetByUids(uIds, &result); err != nil && err != mgo.MongodbNil {
|
||||
//this.module.Errorln(err)
|
||||
return
|
||||
@ -117,7 +122,7 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableVikingSRank, conn_)
|
||||
model := db.NewDBModelByExpired(db.CrossTag(), comm.TableVikingSRank, conn_)
|
||||
|
||||
// 写入排行榜
|
||||
record = &pb.DBVSeasonRecord{
|
||||
@ -216,13 +221,17 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int
|
||||
}
|
||||
|
||||
// 获取排行榜前50的用户名单
|
||||
func (this *ModelSRank) querySRankUser(bossid int, conn_ *db.DBConn) (ranks []string, err error) {
|
||||
func (this *ModelSRank) querySRankUser(bossid int) (ranks []string, err error) {
|
||||
var (
|
||||
result []string
|
||||
conn *db.DBConn
|
||||
)
|
||||
|
||||
tableName := this.TableName + strconv.Itoa(int(bossid))
|
||||
if result, err = conn_.Redis.ZRevRange(tableName, 0, comm.MinRankList).Result(); err != nil {
|
||||
conn, err = db.Cross()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tableName := fmt.Sprintf("%s-%s", db.CrossTag(), this.TableName+strconv.Itoa(int(bossid)))
|
||||
if result, err = conn.Redis.ZRevRange(tableName, 0, comm.MinRankList).Result(); err != nil {
|
||||
//this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -246,7 +255,7 @@ func (this *ModelSRank) raceSettlement() {
|
||||
tableName := this.TableName + strconv.Itoa(int(iBossType))
|
||||
szReward = this.moduleViking.configure.GetVikingRewardConf()
|
||||
|
||||
if result, err = this.DBModel.Redis.ZRevRange(tableName, 0, comm.MaxRankList).Result(); err != nil {
|
||||
if result, err = this.DBModel.Redis.ZRevRange(fmt.Sprintf("%s-%s", this.DBModel, tableName), 0, comm.MaxRankList).Result(); err != nil {
|
||||
this.moduleViking.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -279,7 +288,7 @@ func (this *ModelSRank) raceSettlement() {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
this.DBModel.Redis.DelAllPrefixkey(ctx, "vikingsrank")
|
||||
this.DBModel.Redis.DelAllPrefixkey(ctx, fmt.Sprintf("%s-%s", this.DBModel.ServiceId, "vikingsrank"))
|
||||
|
||||
this.DBModel.DB.DeleteMany(core.SqlTable(this.TableName), bson.M{})
|
||||
return
|
||||
|
@ -192,7 +192,7 @@ func (this *SCompGateRoute) NoticeUserLogin(ctx context.Context, args *pb.Notice
|
||||
log.Errorf("[RPC] NoticeUserLogin err: %v", err)
|
||||
return err
|
||||
}
|
||||
model := db.NewDBModelByExpired(comm.TableSession, conn)
|
||||
model := db.NewDBModelByExpired(this.service.GetTag(), comm.TableSession, conn)
|
||||
user := &pb.CacheUser{
|
||||
Uid: args.UserId,
|
||||
SessionId: args.UserSessionId,
|
||||
|
@ -38,8 +38,9 @@ const (
|
||||
DB_ModelTable core.SqlTable = "model_log"
|
||||
)
|
||||
|
||||
func NewDBModel(tableName string, conn *DBConn) *DBModel {
|
||||
func NewDBModel(sid string, tableName string, conn *DBConn) *DBModel {
|
||||
return &DBModel{
|
||||
ServiceId: sid,
|
||||
TableName: tableName,
|
||||
Expired: time.Minute * 15,
|
||||
conn: conn,
|
||||
@ -47,8 +48,9 @@ func NewDBModel(tableName string, conn *DBConn) *DBModel {
|
||||
DB: conn.Mgo,
|
||||
}
|
||||
}
|
||||
func NewDBModelByExpired(tableName string, conn *DBConn) *DBModel {
|
||||
func NewDBModelByExpired(sid string, tableName string, conn *DBConn) *DBModel {
|
||||
return &DBModel{
|
||||
ServiceId: sid,
|
||||
TableName: tableName,
|
||||
Expired: 0,
|
||||
conn: conn,
|
||||
@ -59,6 +61,7 @@ func NewDBModelByExpired(tableName string, conn *DBConn) *DBModel {
|
||||
|
||||
// DB模型
|
||||
type DBModel struct {
|
||||
ServiceId string
|
||||
TableName string
|
||||
Expired time.Duration //过期时间
|
||||
conn *DBConn //数据源
|
||||
@ -68,15 +71,15 @@ type DBModel struct {
|
||||
|
||||
func (this *DBModel) ukey(uid string) string {
|
||||
if uid == "" {
|
||||
return fmt.Sprintf("%s:member", this.TableName)
|
||||
return fmt.Sprintf("%s-%s:member", this.ServiceId, this.TableName)
|
||||
}
|
||||
return fmt.Sprintf("%s:%s", this.TableName, uid)
|
||||
return fmt.Sprintf("%s-%s:%s", this.ServiceId, this.TableName, uid)
|
||||
}
|
||||
func (this *DBModel) ukeylist(uid string, id string) string {
|
||||
if uid == "" {
|
||||
return fmt.Sprintf("%s:%s", this.TableName, id)
|
||||
return fmt.Sprintf("%s-%s:%s", this.ServiceId, this.TableName, id)
|
||||
}
|
||||
return fmt.Sprintf("%s:%s-%s", this.TableName, uid, id)
|
||||
return fmt.Sprintf("%s-%s:%s-%s", this.ServiceId, this.TableName, uid, id)
|
||||
}
|
||||
func (this *DBModel) InsertModelLogs(table string, uID string, target interface{}) (err error) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user