46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/go-redis/redis/v8"
|
|
"samba/util/rdbkey"
|
|
"strconv"
|
|
)
|
|
|
|
type WaitingRoom struct {
|
|
// 玩法类型
|
|
RoomType int `json:"room_type"`
|
|
// 房间id
|
|
RoomId int `json:"room_id"`
|
|
// 房间内玩家数
|
|
CurrentPlayers int `json:"current_players"`
|
|
// 最大玩家数
|
|
MaxPlayers int `json:"max_players"`
|
|
// 座位与对应的时间戳
|
|
SeatsWithTime []int64 `json:"seats_time"`
|
|
}
|
|
|
|
type ClubWaitingRoomOp struct {
|
|
rdb *redis.Client
|
|
}
|
|
|
|
func NewClubWaitingRoomOp() *ClubWaitingRoomOp {
|
|
return &ClubWaitingRoomOp{rdb: rdbBaseInfo}
|
|
}
|
|
|
|
// Update 更新等待房间信息
|
|
func (op *ClubWaitingRoomOp) Update(clubId int, room *WaitingRoom) error {
|
|
data, err := json.Marshal(room)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return op.rdb.HSet(context.TODO(), rdbkey.ClubWaitingRoomKey(clubId), room.RoomId, string(data)).Err()
|
|
|
|
}
|
|
|
|
// Delete 删除等待房间信息
|
|
func (op *ClubWaitingRoomOp) Delete(clubId int, roomId int) error {
|
|
return op.rdb.HDel(context.TODO(), rdbkey.ClubWaitingRoomKey(clubId), strconv.Itoa(roomId)).Err()
|
|
}
|