26 lines
492 B
Go
26 lines
492 B
Go
package bootstrap
|
|
|
|
import (
|
|
"Blog/internal/client"
|
|
"context"
|
|
|
|
red "github.com/redis/go-redis/v9"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func initRedis() {
|
|
addr := Config.Database.Redis.Addr
|
|
db := Config.Database.Redis.Db
|
|
client.RedisClient = red.NewClient(&red.Options{
|
|
Addr: addr,
|
|
DB: db, // 默认DB 0
|
|
})
|
|
ctx := context.Background()
|
|
sc := client.RedisClient.Ping(ctx)
|
|
pong := sc.Val()
|
|
if pong == "PONG" {
|
|
logrus.Info("Redis连接成功")
|
|
client.RedisClient.FlushDB(ctx)
|
|
}
|
|
}
|