Вывод строки подключения redis
This commit is contained in:
14
app/cache/cache.go
vendored
14
app/cache/cache.go
vendored
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user