mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:22:26 +08:00
玩家管理模块接入redis,已完整实现好友、多人世界的跨服交互功能
This commit is contained in:
@@ -8,28 +8,34 @@ import (
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
)
|
||||
|
||||
type Dao struct {
|
||||
client *mongo.Client
|
||||
db *mongo.Database
|
||||
mongo *mongo.Client
|
||||
db *mongo.Database
|
||||
}
|
||||
|
||||
func NewDao() (r *Dao) {
|
||||
r = new(Dao)
|
||||
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url)
|
||||
clientOptions := options.Client().ApplyURI(config.CONF.Database.Url).SetMinPoolSize(10).SetMaxPoolSize(100)
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
logger.Error("mongo connect error: %v", err)
|
||||
return nil
|
||||
}
|
||||
r.client = client
|
||||
err = client.Ping(context.TODO(), readpref.Primary())
|
||||
if err != nil {
|
||||
logger.Error("mongo ping error: %v", err)
|
||||
return nil
|
||||
}
|
||||
r.mongo = client
|
||||
r.db = client.Database("dispatch_hk4e")
|
||||
return r
|
||||
}
|
||||
|
||||
func (d *Dao) CloseDao() {
|
||||
err := d.client.Disconnect(context.TODO())
|
||||
err := d.mongo.Disconnect(context.TODO())
|
||||
if err != nil {
|
||||
logger.Error("mongo close error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user