index.go 943 Bytes
package configs

import (
	"apigame/common/svdto"
	"apigame/util/zjson"
	"apigame/util/zredis"
	"fmt"
)

//	func GetConfigRedis[T svconfig.IDtoData](gameId string) (result *T, has bool) {
//		t = new(T)
//		var rule = t.GetRule(gameId)
//		return
//	}
func GetConfigMysql[T svdto.IDtoData](gameId string, t T) (result *T, has bool) {
	return
}

func GetConfig[T svdto.IDtoData](gameId string, t T) (has bool) {
	has = CacheLoad[T](gameId, t)
	if !has {

	}
	return
}

func CacheSave(gameId string, conf svdto.IDtoData) {
	rule := conf.GetRule(gameId)
	_ = zredis.SetEx(zredis.GetConn(), rule.CacheKey, zjson.Str(conf), rule.CacheTime)
}

func CacheLoad[T svdto.IDtoData](gameId string, t T) (has bool) {
	has = true
	rule := t.GetRule(gameId)
	text, err := zredis.Get(zredis.GetConn(), rule.CacheKey)
	if err != nil {
		has = false
		return
	}
	err = zjson.Obj(text, &t)
	if err != nil {
		fmt.Println(err)
		has = false
		return
	}
	return
}