samba/util/model/userQuickMatch.go
2025-06-04 09:51:39 +08:00

46 lines
1.3 KiB
Go

package model
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
"samba/pkg/log"
"samba/util/rdbkey"
"strconv"
)
type UserQuickMatch struct {
UserId int64 `json:"user_id"`
PlayType int `json:"play_type"`
RoomType int64 `json:"room_type"` // 该玩法最近的一局房间配置id
}
type UserQuickMatchOp struct {
rdb *redis.Client
}
func NewUserQuickMatchOp() *UserQuickMatchOp {
return &UserQuickMatchOp{rdb: rdbBaseInfo}
}
// 俱乐部玩家获取最近游玩的房间
func (op *UserQuickMatchOp) GetRoomType(userId int64, playType int) int {
val, err := op.rdb.HGet(context.Background(), rdbkey.UserQuickMatchKey(userId), fmt.Sprintf("%v", playType)).Result()
if err == nil {
playType, _ := strconv.ParseInt(val, 10, 64)
return int(playType)
}
_ = op.rdb.Expire(context.Background(), rdbkey.UserQuickMatchKey(userId), redis30day).Err()
return 0
}
// 俱乐部玩家保存最近游玩的房间,方便下次快速匹配
func (op *UserQuickMatchOp) Save(userId int64, playType, roomType int) error {
err := op.rdb.HSet(context.Background(), rdbkey.UserQuickMatchKey(userId), playType, roomType).Err()
if err != nil {
log.Error(fmt.Sprintf("user:%v save quick play type:%v err:%v", userId, playType, err))
}
_ = op.rdb.Expire(context.Background(), rdbkey.UserQuickMatchKey(userId), redis30day).Err()
return err
}