27 lines
551 B
Go
27 lines
551 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
goredis "github.com/redis/go-redis/v9"
|
|
|
|
"github.com/example/remote-access-platform/backend/internal/platform/config"
|
|
)
|
|
|
|
func Open(ctx context.Context, cfg config.RedisConfig) (*goredis.Client, error) {
|
|
client := goredis.NewClient(&goredis.Options{
|
|
Addr: cfg.Addr,
|
|
Password: cfg.Password,
|
|
DB: cfg.DB,
|
|
DialTimeout: cfg.DialTimeout,
|
|
})
|
|
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
_ = client.Close()
|
|
return nil, fmt.Errorf("ping redis: %w", err)
|
|
}
|
|
|
|
return client, nil
|
|
}
|