1234567891011121314151617181920212223242526 |
- package initialize
- import (
- "context"
- "github.com/sirupsen/logrus"
- "lc-base-frame/global"
- "github.com/redis/go-redis/v9"
- "go.uber.org/zap"
- )
- func Redis() {
- redisCfg := global.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 {
- logrus.Error("redis connect ping failed, err:", zap.Error(err))
- } else {
- logrus.Info("redis connect ping response:", zap.String("pong", pong))
- global.GVA_REDIS = client
- }
- }
|