redis 批量清除排行数据 性能测试
This commit is contained in:
parent
8c340f6955
commit
fcf7922c42
@ -9,6 +9,8 @@ import (
|
|||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
@ -16,7 +18,9 @@ import (
|
|||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/cron"
|
"go_dreamfactory/lego/sys/cron"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/lego/sys/redis/pipe"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
@ -62,8 +66,11 @@ func (this *SeasonPagoda) Start() (err error) {
|
|||||||
if db.IsCross() {
|
if db.IsCross() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//time.Sleep(time.Second * 1)
|
||||||
|
//this.DbTest()
|
||||||
conn, err := db.Cross()
|
conn, err := db.Cross()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
model := db.NewDBModel(comm.TableServerData, 0, conn)
|
model := db.NewDBModel(comm.TableServerData, 0, conn)
|
||||||
|
|
||||||
_len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{})
|
_len, err1 := model.DB.CountDocuments(comm.TableServerData, bson.M{})
|
||||||
@ -85,7 +92,6 @@ func (this *SeasonPagoda) Start() (err error) {
|
|||||||
model.DB.InsertOne(comm.TableServerData, server)
|
model.DB.InsertOne(comm.TableServerData, server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,3 +194,81 @@ func (this *SeasonPagoda) TimerSeasonStar() {
|
|||||||
}
|
}
|
||||||
//this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
//this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *SeasonPagoda) DbTest() {
|
||||||
|
conn, err := db.Cross()
|
||||||
|
model1 := db.NewDBModel(comm.TableVikingRank, time.Hour, conn)
|
||||||
|
model1.Redis.Delete("vikingRank2")
|
||||||
|
_d, err := model1.Redis.Keys("vikingrank:*")
|
||||||
|
if err == nil {
|
||||||
|
for _, v := range _d {
|
||||||
|
model1.Redis.Delete(v)
|
||||||
|
}
|
||||||
|
fmt.Printf("%v", _d)
|
||||||
|
}
|
||||||
|
star := configure.Now()
|
||||||
|
for i := 1; i < 10000; i++ {
|
||||||
|
|
||||||
|
new := &pb.DBVikingRank{
|
||||||
|
Id: primitive.NewObjectID().Hex(),
|
||||||
|
Uid: "mmmxxx" + strconv.Itoa(i),
|
||||||
|
Difficulty: int32(i) % 10,
|
||||||
|
Bosstype: 2,
|
||||||
|
Nickname: "helo",
|
||||||
|
Icon: "",
|
||||||
|
Lv: 120,
|
||||||
|
Leadpos: 1,
|
||||||
|
Line: make([]*pb.LineUp, 5),
|
||||||
|
CostTime: 12000 + int32(i),
|
||||||
|
}
|
||||||
|
model1.AddList(new.Uid, new.Id, new)
|
||||||
|
var (
|
||||||
|
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||||
|
menbers *redis.Z
|
||||||
|
tableName string
|
||||||
|
score int64
|
||||||
|
)
|
||||||
|
score = int64(i)<<31 + int64(math.MaxInt32-new.CostTime)
|
||||||
|
tableName = "vikingRank" + strconv.Itoa(int(new.Bosstype))
|
||||||
|
//vikingrank:mmmxxx1-63bbb137b96efbd321222ce7
|
||||||
|
strKey := "vikingrank:" + new.Uid + "-" + new.Id // 自定义key
|
||||||
|
menbers = &redis.Z{Score: float64(score), Member: strKey}
|
||||||
|
|
||||||
|
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||||
|
|
||||||
|
dock, err1 := cmd.Result()
|
||||||
|
if err1 != nil {
|
||||||
|
this.module.Errorln(dock, err1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := pipe.Exec(); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.module.Debugf("=====%d,", time.Since(star).Milliseconds())
|
||||||
|
if true {
|
||||||
|
var (
|
||||||
|
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||||
|
szRank []*pb.DBVikingRank
|
||||||
|
)
|
||||||
|
// 降序
|
||||||
|
rd := pipe.ZRevRange("vikingRank"+strconv.Itoa(2), 0, -1)
|
||||||
|
|
||||||
|
if _, err := pipe.Exec(); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_dataList := rd.Val()
|
||||||
|
for _, v := range _dataList {
|
||||||
|
result := &pb.DBVikingRank{}
|
||||||
|
|
||||||
|
if err := model1.Redis.HGetAll(v, result); err == nil {
|
||||||
|
szRank = append(szRank, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
this.module.Debugf("%v", szRank)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user