28 lines
609 B
Go
28 lines
609 B
Go
package db
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"github.com/redis/go-redis/v9"
|
||
"log"
|
||
"qnc-server/config"
|
||
)
|
||
|
||
var RedisClient redis.UniversalClient
|
||
|
||
func InitRedis() {
|
||
var client redis.UniversalClient
|
||
client = redis.NewClient(&redis.Options{
|
||
Addr: config.ConfigData.Redis.Addr,
|
||
Password: config.ConfigData.Redis.Password,
|
||
DB: config.ConfigData.Redis.DB,
|
||
})
|
||
pong, err := client.Ping(context.Background()).Result()
|
||
if err != nil {
|
||
log.Fatalf("redis connect ping failed, err:", err.Error())
|
||
} else {
|
||
fmt.Printf("redis start,redis connect ping response: %s", pong)
|
||
RedisClient = client
|
||
}
|
||
}
|