34 lines
741 B
Go
34 lines
741 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"gitea.com/bitwsd/document_ai/config"
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
var RedisClient *redis.Client
|
|
|
|
func InitRedisClient(config config.RedisConfig) {
|
|
fmt.Println("Initializing Redis client...")
|
|
RedisClient = redis.NewClient(&redis.Options{
|
|
Addr: config.Addr,
|
|
Password: config.Password,
|
|
DB: config.DB,
|
|
DialTimeout: 10 * time.Second,
|
|
ReadTimeout: 10 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
})
|
|
|
|
fmt.Println("Pinging Redis server...")
|
|
_, err := RedisClient.Ping(context.Background()).Result()
|
|
if err != nil {
|
|
fmt.Printf("Init redis client failed, err: %v\n", err)
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println("Redis client initialized successfully.")
|
|
}
|