Вывод строки подключения redis

This commit is contained in:
2025-10-02 01:12:46 +08:00
parent 10c3b8f5c1
commit dc61d47b66

14
app/cache/cache.go vendored
View File

@@ -10,28 +10,30 @@ import (
"axenov/iptv-checker/app/config"
"context"
"fmt"
"github.com/redis/go-redis/v9"
"log"
"strconv"
"github.com/redis/go-redis/v9"
)
func Init(cfg *config.CacheConfig) *redis.Client {
redis := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port))),
redisUrl := fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port)))
redisClient := redis.NewClient(&redis.Options{
Addr: redisUrl,
DB: int(cfg.Db),
PoolSize: 1000,
ReadTimeout: -1,
WriteTimeout: -1,
})
client := redis.Conn()
client := redisClient.Conn()
ctx := context.Background()
err := client.Ping(ctx).Err()
if err == nil {
log.Println("Connected to cache DB")
log.Println("Connected to cache DB:", redisUrl)
cfg.IsActive = true
} else {
log.Println("Error while connecting to cache DB, program may work not as expected:", err)
}
return redis
return redisClient
}