37 lines
815 B
Go
37 lines
815 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.RedisConfig) *redis.Client {
|
|
rdb := 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 := rdb.Conn()
|
|
|
|
var ctx context.Context
|
|
if client.Ping(ctx).Err() != nil {
|
|
log.Println("Error while connecting to Redis", cfg.Host, cfg.Port, cfg.Db)
|
|
} else {
|
|
log.Println("Connected to Redis", cfg.Host, cfg.Port, cfg.Db)
|
|
}
|
|
|
|
return rdb
|
|
}
|