2 Star 0 Fork 1

taotechip/modules

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
init.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
kyugao 提交于 2025-04-02 17:36 +08:00 . 2.0_alpha
package cache
import (
"fmt"
"time"
"gitee.com/kyugao/ujson"
"github.com/gomodule/redigo/redis"
"github.com/jinzhu/configor"
"github.com/rs/zerolog/log"
)
var Config = struct {
Ip string
Port string
Db string
Session struct {
Db string
TempSessionAliveSeconds int
ActiveSeconds int
Refresh bool
}
}{}
var pool redis.Pool
func init() {
err := configor.Load(&Config, "conf/cache.yml")
if err != nil {
panic(err)
}
log.Info().Msgf("config=%s", ujson.ToJsonRawString(&Config))
address := fmt.Sprintf("%s:%s", Config.Ip, Config.Port)
pool = redis.Pool{
Dial: func() (c redis.Conn, err error) {
c, err = redis.Dial("tcp", address)
if err != nil {
panic(err)
}
return
},
TestOnBorrow: nil,
MaxIdle: 3,
MaxActive: 20,
IdleTimeout: 240 * time.Second,
Wait: false,
MaxConnLifetime: 0,
}
}
func GetConn() (conn redis.Conn) {
conn = GetConnWithNum(Config.Db)
return
}
func GetConnWithNum(dbNum string) (conn redis.Conn) {
conn = pool.Get()
conn.Do("SELECT", dbNum)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/taotechip/modules.git
git@gitee.com:taotechip/modules.git
taotechip
modules
modules
v1.10.5

搜索帮助