3 Star 6 Fork 0

workits/pkgs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
workits 提交于 1年前 . add more params of redis
package cachex
import (
"context"
"time"
"github.com/redis/go-redis/v9"
)
var Client redis.UniversalClient
var ctx context.Context
// InitCache 初始化缓存
func InitCache(cfg Config) error {
Client = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: cfg.Addrs,
Username: cfg.Username,
Password: cfg.Password,
SentinelUsername: cfg.SentinelUsername,
SentinelPassword: cfg.SentinelPassword,
DB: cfg.DB,
MasterName: cfg.MasterName,
PoolFIFO: cfg.PoolFIFO,
PoolSize: cfg.PoolSize,
MinIdleConns: cfg.MinIdleConns,
MaxIdleConns: cfg.MaxIdleConns,
DialTimeout: time.Duration(cfg.DialTimeout) * time.Second,
ReadTimeout: time.Duration(cfg.ReadTimeout) * time.Second,
WriteTimeout: time.Duration(cfg.WriteTimeout) * time.Second,
PoolTimeout: time.Duration(cfg.PoolTimeout) * time.Second,
MaxRetries: cfg.MaxRetries,
MinRetryBackoff: time.Duration(cfg.MinRetryBackoff) * time.Millisecond,
MaxRetryBackoff: time.Duration(cfg.MaxRetryBackoff) * time.Millisecond,
})
ctx = context.Background()
return Client.Ping(ctx).Err()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/workits/pkgs.git
git@gitee.com:workits/pkgs.git
workits
pkgs
pkgs
v0.0.1

搜索帮助