From 9608ac479569cf894c5ef1a6c87f7c506b884cf2 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Tue, 17 Dec 2024 00:23:35 +0800 Subject: [PATCH] redisConf --- core.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core.go b/core.go index a152416..0beec8c 100644 --- a/core.go +++ b/core.go @@ -136,6 +136,23 @@ func (core *Core) Init() { fmt.Println("init redis client err: ", err) } } + +func (core *Core) GetRedisCliFromConf(conf RedisConfig) (*redis.Client, error) { + client := redis.NewClient(&redis.Options{ + Addr: conf.Url, + Password: conf.Password, //默认空密码 + DB: conf.Index, //使用默认数据库 + }) + pong, err := client.Ping().Result() + if pong == "PONG" && err == nil { + return client, err + } else { + fmt.Println("redis状态不可用:", conf.Url, conf.Password, conf.Index, err) + } + + return client, nil +} + func (core *Core) GetRemoteRedisLocalCli() (*redis.Client, error) { ru := core.Cfg.RedisConf.Url rp := core.Cfg.RedisConf.Password