23 lines
444 B
Go
23 lines
444 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
|
|
goredis "github.com/redis/go-redis/v9"
|
|
|
|
"scheduler-backend/pkg/config"
|
|
)
|
|
|
|
func Connect(ctx context.Context, cfg config.Config) (*goredis.Client, error) {
|
|
client := goredis.NewClient(&goredis.Options{
|
|
Addr: cfg.RedisAddr,
|
|
Username: cfg.RedisUsername,
|
|
Password: cfg.RedisPassword,
|
|
})
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
_ = client.Close()
|
|
return nil, err
|
|
}
|
|
return client, nil
|
|
}
|