71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package db
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type (
|
|
ISys interface {
|
|
//本服数据连接
|
|
Local() (conn *DBConn, err error)
|
|
//本服数据连接
|
|
Cross() (conn *DBConn, err error)
|
|
//跨服列表数据层连接
|
|
ServerDBConn(stage string) (conn *DBConn, err error)
|
|
///获取区服列表标签
|
|
GetServerTags() []string
|
|
//更新数据过期
|
|
UpDateModelExpired(key string, childs map[string]struct{}, expired time.Duration)
|
|
}
|
|
//过期数据
|
|
ModelDataExpired struct {
|
|
key string //主key
|
|
keys map[string]struct{} //数据集合
|
|
expired time.Time //过期时间
|
|
}
|
|
)
|
|
|
|
var defsys ISys
|
|
|
|
func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
|
var options *Options
|
|
if options, err = newOptions(config, option...); err != nil {
|
|
return
|
|
}
|
|
defsys, err = newSys(options)
|
|
|
|
// defsys.Local().Redis.GetClient().FlushAll(context.TODO())
|
|
return
|
|
}
|
|
|
|
func NewSys(option ...Option) (sys ISys, err error) {
|
|
var options *Options
|
|
if options, err = newOptionsByOption(option...); err != nil {
|
|
return
|
|
}
|
|
defsys, err = newSys(options)
|
|
return
|
|
}
|
|
|
|
func Local() (conn *DBConn, err error) {
|
|
return defsys.Local()
|
|
}
|
|
|
|
func Cross() (conn *DBConn, err error) {
|
|
return defsys.Cross()
|
|
}
|
|
|
|
func ServerDBConn(stage string) (conn *DBConn, err error) {
|
|
return defsys.ServerDBConn(stage)
|
|
}
|
|
|
|
///获取区服列表标签
|
|
func GetServerTags() []string {
|
|
return defsys.GetServerTags()
|
|
}
|
|
|
|
//更新数据过期
|
|
func UpDateModelExpired(key string, childs map[string]struct{}, expired time.Duration) {
|
|
defsys.UpDateModelExpired(key, childs, expired)
|
|
}
|