2022-10-09 23:26:27 +03:00
|
|
|
package proxyd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2023-09-14 22:36:24 +03:00
|
|
|
"github.com/redis/go-redis/v9"
|
2022-10-09 23:26:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewRedisClient(url string) (*redis.Client, error) {
|
|
|
|
opts, err := redis.ParseURL(url)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
|
|
return nil, wrapErr(err, "error connecting to redis")
|
|
|
|
}
|
|
|
|
return client, nil
|
|
|
|
}
|