24 lines
443 B
Go
24 lines
443 B
Go
|
|
package redis
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
goredis "github.com/redis/go-redis/v9"
|
||
|
|
|
||
|
|
"github.com/geo-platform/tenant-api/internal/shared/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
func NewClient(ctx context.Context, cfg config.RedisConfig) (*goredis.Client, error) {
|
||
|
|
client := goredis.NewClient(&goredis.Options{
|
||
|
|
Addr: cfg.Addr,
|
||
|
|
DB: cfg.DB,
|
||
|
|
})
|
||
|
|
|
||
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
||
|
|
return nil, fmt.Errorf("ping redis: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
return client, nil
|
||
|
|
}
|