You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
74 lines
2.2 KiB
package initialize
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gin_server_admin/global"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func Redis() {
|
|
redisCfg := global.GVA_CONFIG.Redis
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: redisCfg.Addr,
|
|
Password: redisCfg.Password, // no password set
|
|
DB: redisCfg.DB, // use default DB
|
|
})
|
|
pong, err := client.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
|
|
} else {
|
|
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
|
|
global.GVA_REDIS = client
|
|
}
|
|
}
|
|
|
|
func WechatRedis() {
|
|
redisCfg := global.GVA_CONFIG.WechatRedis
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: redisCfg.Addr,
|
|
Password: redisCfg.Password, // no password set
|
|
DB: redisCfg.DB, // use default DB
|
|
})
|
|
pong, err := client.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
global.GVA_LOG.Error("企业微信Redis-->1链接失败!, err:", zap.Any("err", err))
|
|
} else {
|
|
global.GVA_LOG.Info("企业微信Redis--->1链接成功:", zap.String("pong", pong))
|
|
global.GVA_REDIS_WeChat = client
|
|
}
|
|
}
|
|
|
|
func WechatRedis2() {
|
|
redisCfg := global.GVA_CONFIG.WechatRedis2
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: redisCfg.Addr,
|
|
Password: redisCfg.Password, // no password set
|
|
DB: redisCfg.DB, // use default DB
|
|
})
|
|
pong, err := client.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
global.GVA_LOG.Error("企业微信Redis--->2链接失败!, err:", zap.Any("err", err))
|
|
} else {
|
|
global.GVA_LOG.Info("企业微信Redis--->2链接成功:", zap.String("pong", pong))
|
|
global.GVA_REDIS_WeChat2 = client
|
|
}
|
|
}
|
|
|
|
func WechatRedis5() {
|
|
redisCfg := global.GVA_CONFIG.WechatRedis5
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: redisCfg.Addr,
|
|
Password: redisCfg.Password, // no password set
|
|
DB: redisCfg.DB, // use default DB
|
|
})
|
|
pong, err := client.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
global.GVA_LOG.Error("企业微信Redis--->5链接失败!, err:", zap.Any("err", err))
|
|
} else {
|
|
global.GVA_LOG.Info("企业微信Redis--->5链接成功:", zap.String("pong", pong))
|
|
global.GVA_REDIS_WeChat5 = client
|
|
}
|
|
}
|
|
|