31 lines
603 B
Go
31 lines
603 B
Go
package db
|
|
|
|
import (
|
|
"apskel-pos-be/config"
|
|
"fmt"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func NewRedisClient(c config.Redis) (*redis.Client, error) {
|
|
opts := &redis.Options{
|
|
Addr: c.Addr(),
|
|
Password: c.Password,
|
|
DB: c.DB,
|
|
DialTimeout: c.ParseDialTimeout(),
|
|
ReadTimeout: c.ParseReadTimeout(),
|
|
WriteTimeout: c.ParseWriteTimeout(),
|
|
}
|
|
if c.PoolSize > 0 {
|
|
opts.PoolSize = c.PoolSize
|
|
}
|
|
if c.MinIdleConnections > 0 {
|
|
opts.MinIdleConns = c.MinIdleConnections
|
|
}
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
fmt.Println("Successfully connected to Redis")
|
|
return client, nil
|
|
}
|