package database import ( "context" "log" "github.com/redis/go-redis/v9" ) var RedisTemplate *redis.Client func init() { RedisTemplate = redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", // 没有密码,默认值 DB: 0, // 默认DB 0 }) sc := RedisTemplate.Ping(context.Background()) pong := sc.Val() if pong == "PONG" { log.Println("Redis连接成功") } }