zhangqian
2023-08-26 5193dcb9336e853502baf8a539d3f45efebe2f86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package initialize
 
import (
    "context"
 
    "srm/global"
 
    "github.com/redis/go-redis/v9"
    "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.Error(err))
    } else {
        global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
        global.GVA_REDIS = client
    }
}