1234567891011121314151617181920212223242526 |
- package initialize
- import (
- "context"
- "github.com/flipped-aurora/gin-vue-admin/server/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
- }
- }
|