1 Star 0 Fork 0

康斯坦丁龙傲天 / gredis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
conn.go 951 Bytes
一键复制 编辑 原始数据 按行查看 历史
package gredis
import (
"time"
"github.com/gomodule/redigo/redis"
)
type Conf struct {
Addr string
MaxIdle int
MaxActive int
IdleTimeout time.Duration
Wait bool
DB string
PassWord string
}
type ReidsConn struct {
redis.Conn
}
func (c *Conf) SetPool() redis.Pool {
pool := redis.Pool{
MaxIdle: c.MaxIdle,
MaxActive: c.MaxActive,
IdleTimeout: c.IdleTimeout,
Wait: c.Wait,
Dial: func() (redis.Conn, error) {
conn, err := redis.Dial("tcp", c.Addr)
if err != nil {
return conn, err
}
if c.PassWord != "" {
_, err = conn.Do("auth", c.PassWord)
if err != nil {
return conn, err
}
}
if c.DB != "" {
_, err = conn.Do("select", c.DB)
if err != nil {
return conn, err
}
}
return conn, err
},
}
return pool
}
func SetConn(pool redis.Pool) ReidsConn {
defer pool.Close()
conn := ReidsConn{
pool.Get(),
}
return conn
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/constantine-dragon/gredis.git
git@gitee.com:constantine-dragon/gredis.git
constantine-dragon
gredis
gredis
2ec97ade0102

搜索帮助

344bd9b3 5694891 D2dac590 5694891