38 lines
849 B
Go
38 lines
849 B
Go
/*
|
|
* Copyright (c) 2025, Антон Аксенов
|
|
* This file is part of iptvc project
|
|
* MIT License: https://git.axenov.dev/IPTV/iptvc/src/branch/master/LICENSE
|
|
*/
|
|
|
|
package cache
|
|
|
|
import (
|
|
"axenov/iptv-checker/app/config"
|
|
"context"
|
|
"fmt"
|
|
"github.com/redis/go-redis/v9"
|
|
"log"
|
|
"strconv"
|
|
)
|
|
|
|
func Init(cfg *config.CacheConfig) *redis.Client {
|
|
redis := redis.NewClient(&redis.Options{
|
|
Addr: fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port))),
|
|
DB: int(cfg.Db),
|
|
PoolSize: 1000,
|
|
ReadTimeout: -1,
|
|
WriteTimeout: -1,
|
|
})
|
|
client := redis.Conn()
|
|
ctx := context.Background()
|
|
err := client.Ping(ctx).Err()
|
|
if err == nil {
|
|
log.Println("Connected to cache DB")
|
|
cfg.IsActive = true
|
|
} else {
|
|
log.Println("Error while connecting to cache DB, program may work not as expected:", err)
|
|
}
|
|
|
|
return redis
|
|
}
|