Вывод строки подключения 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" "axenov/iptv-checker/app/config"
"context" "context"
"fmt" "fmt"
"github.com/redis/go-redis/v9"
"log" "log"
"strconv" "strconv"
"github.com/redis/go-redis/v9"
) )
func Init(cfg *config.CacheConfig) *redis.Client { func Init(cfg *config.CacheConfig) *redis.Client {
redis := redis.NewClient(&redis.Options{ redisUrl := fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port)))
Addr: fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port))), redisClient := redis.NewClient(&redis.Options{
Addr: redisUrl,
DB: int(cfg.Db), DB: int(cfg.Db),
PoolSize: 1000, PoolSize: 1000,
ReadTimeout: -1, ReadTimeout: -1,
WriteTimeout: -1, WriteTimeout: -1,
}) })
client := redis.Conn() client := redisClient.Conn()
ctx := context.Background() ctx := context.Background()
err := client.Ping(ctx).Err() err := client.Ping(ctx).Err()
if err == nil { if err == nil {
log.Println("Connected to cache DB") log.Println("Connected to cache DB:", redisUrl)
cfg.IsActive = true cfg.IsActive = true
} else { } else {
log.Println("Error while connecting to cache DB, program may work not as expected:", err) log.Println("Error while connecting to cache DB, program may work not as expected:", err)
} }
return redis return redisClient
} }