去除单机模式对redis中间件的依赖

This commit is contained in:
flswld committed 2024-09-03 18:04:16 +08:00
1 parent 2e665471fe
commit 3966606689
21 files changed
+433 -334

No files matched your search

+7 -51
View File
@@ -10,9 +10,13 @@ import (
)
type Region struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
Ec2bData []byte `bson:"ec2b_data"`
NextUid uint32 `bson:"next_uid"`
ID primitive.ObjectID `bson:"_id,omitempty"`
Ec2bData []byte `bson:"ec2b_data"`
NextUid uint32 `bson:"next_uid"`
StopServer bool `bson:"stop_server"`
StopServerStartTime uint32 `bson:"stop_server_start_time"`
StopServerEndTime uint32 `bson:"stop_server_end_time"`
IpAddrWhiteList []string `bson:"ip_addr_white_list"`
}
func (d *Dao) InsertRegion(region *Region) error {
@@ -54,51 +58,3 @@ func (d *Dao) QueryRegion() (*Region, error) {
}
return region, nil
}
type StopServerInfo struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
StopServer bool `bson:"stop_server"`
StartTime uint32 `bson:"start_time"`
EndTime uint32 `bson:"end_time"`
IpAddrWhiteList []string `bson:"ip_addr_white_list"`
}
func (d *Dao) InsertStopServerInfo(stopServerInfo *StopServerInfo) error {
db := d.db.Collection("stop_server_info")
_, err := db.InsertOne(context.TODO(), stopServerInfo)
if err != nil {
return err
}
return nil
}
func (d *Dao) UpdateStopServerInfo(stopServerInfo *StopServerInfo) error {
db := d.db.Collection("stop_server_info")
_, err := db.UpdateMany(
context.TODO(),
bson.D{},
bson.D{{"$set", stopServerInfo}},
)
if err != nil {
return err
}
return nil
}
func (d *Dao) QueryStopServerInfo() (*StopServerInfo, error) {
db := d.db.Collection("stop_server_info")
result := db.FindOne(
context.TODO(),
bson.D{},
)
stopServerInfo := new(StopServerInfo)
err := result.Decode(stopServerInfo)
if err != nil {
if errors.Is(err, mongo.ErrNoDocuments) {
return nil, nil
} else {
return nil, err
}
}
return stopServerInfo, nil
}