1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
redis.go 1.94 KB
Copy Edit Raw Blame History
kzangv authored 2023-03-15 16:15 . fixed
package component
import (
"fmt"
"gitee.com/kzangv/gsf-fof/component/define"
"gitee.com/kzangv/gsf-fof/gsf"
"gitee.com/kzangv/gsf-fof/logger"
"github.com/urfave/cli/v2"
)
type Redis struct {
Cfg define.ComponentRedis
Clts map[string]*RedisClient
Log logger.Interface
}
func (c *Redis) CliFlags() []cli.Flag {
fs := make([][]cli.Flag, 0, len(c.Clts)+1)
fs = append(fs, []cli.Flag{
&cli.IntFlag{Name: "redis-sr-timeout", Usage: "redis connect socket read timeout", Value: 15, Destination: &c.Cfg.MaxReadTime},
&cli.IntFlag{Name: "redis-sw-timeout", Usage: "redis connect socket write timeout", Value: 15, Destination: &c.Cfg.MaxWriteTime},
&cli.IntFlag{Name: "redis-cr-timeout", Usage: "redis client request timeout", Value: 15, Destination: &c.Cfg.MaxRequestTime},
&cli.IntFlag{Name: "redis-check-idle-time", Usage: "redis idle timeout", Value: 30, Destination: &c.Cfg.IdleCheckTime},
&cli.IntFlag{Name: "redis-threshold", Usage: "redis slow request threshold", Value: 100, Destination: &c.Cfg.SlowThreshold},
})
for name, clt := range c.Clts {
fs = append(fs, clt.CliFlags(name))
}
l := 0
for k := range fs {
l += len(fs[k])
}
ret := make([]cli.Flag, 0, l)
for k := range fs {
ret = append(ret, fs[k]...)
}
return ret
}
func (c *Redis) Init(l logger.Interface, cfg *gsf.AppConfig, _ *cli.Context) error {
c.Log = l
// 打印链接信息
for k, v := range c.Clts {
v.Init(cfg.Env(), c)
msg := fmt.Sprintf("Init Redis (%s) config", k)
if define.PrintfDSN {
msg = fmt.Sprintf("%s (%s/%d)", msg, v.Config().Addr, v.Config().DB)
}
l.WarnForce(msg)
}
return nil
}
func (c *Redis) Run() (err error) {
for name := range c.Clts {
if err = c.LoadOne(name); err != nil {
break
}
}
return err
}
func (c *Redis) LoadOne(name string) (err error) {
if clt, ok := c.Clts[name]; ok {
err = clt.Load(name)
} else {
err = fmt.Errorf("Redis (%s) config no find", name)
}
return err
}
func (c *Redis) Close() error {
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.3

Search