redis.go 620 字节
Newer Older
1
package initialize
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3

import (
4
	"context"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5
	"gin-vue-admin/global"
6 7

	"github.com/go-redis/redis/v8"
8
	"go.uber.org/zap"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
9 10
)

11
func Redis() {
12
	redisCfg := global.GVA_CONFIG.Redis
Mr.奇淼('s avatar
Mr.奇淼( 已提交
13
	client := redis.NewClient(&redis.Options{
14 15 16
		Addr:     redisCfg.Addr,
		Password: redisCfg.Password, // no password set
		DB:       redisCfg.DB,       // use default DB
Mr.奇淼('s avatar
Mr.奇淼( 已提交
17
	})
18
	pong, err := client.Ping(context.Background()).Result()
Mr.奇淼('s avatar
Mr.奇淼( 已提交
19
	if err != nil {
20
		global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
Mr.奇淼('s avatar
Mr.奇淼( 已提交
21
	} else {
22
		global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23 24 25
		global.GVA_REDIS = client
	}
}