Вывод строки подключения 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"
|
"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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user