2020-04-05 08:18:19 +00:00
|
|
|
package initialize
|
2020-04-04 13:39:07 +00:00
|
|
|
|
|
|
|
|
import (
|
2021-07-12 11:23:56 +00:00
|
|
|
"context"
|
2021-08-21 03:01:34 +00:00
|
|
|
|
2021-08-23 15:13:24 +00:00
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
2021-07-12 11:23:56 +00:00
|
|
|
|
2023-08-04 09:03:21 +00:00
|
|
|
"github.com/redis/go-redis/v9"
|
2020-09-05 03:55:51 +00:00
|
|
|
"go.uber.org/zap"
|
2020-04-04 13:39:07 +00:00
|
|
|
)
|
|
|
|
|
|
2020-04-05 01:18:25 +00:00
|
|
|
func Redis() {
|
2020-04-05 08:18:19 +00:00
|
|
|
redisCfg := global.GVA_CONFIG.Redis
|
2020-04-04 13:39:07 +00:00
|
|
|
client := redis.NewClient(&redis.Options{
|
2020-04-05 01:18:25 +00:00
|
|
|
Addr: redisCfg.Addr,
|
|
|
|
|
Password: redisCfg.Password, // no password set
|
|
|
|
|
DB: redisCfg.DB, // use default DB
|
2020-04-04 13:39:07 +00:00
|
|
|
})
|
2021-07-12 11:23:56 +00:00
|
|
|
pong, err := client.Ping(context.Background()).Result()
|
2020-04-04 13:39:07 +00:00
|
|
|
if err != nil {
|
2021-11-15 18:13:54 +00:00
|
|
|
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Error(err))
|
2023-11-18 13:01:44 +00:00
|
|
|
panic(err)
|
2020-04-04 13:39:07 +00:00
|
|
|
} else {
|
2021-04-04 13:32:23 +00:00
|
|
|
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
|
2020-04-04 13:39:07 +00:00
|
|
|
global.GVA_REDIS = client
|
|
|
|
|
}
|
|
|
|
|
}
|