2023-12-31 12:22:03 +00:00
|
|
|
package initialize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
)
|
|
|
|
|
2024-01-11 12:07:17 +00:00
|
|
|
func Redis(ctx context.Context, cfg Config) (*redis.Client, error) {
|
2023-12-31 12:22:03 +00:00
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
|
|
Addr: cfg.RedisAddr,
|
|
|
|
Password: cfg.RedisPassword,
|
|
|
|
DB: cfg.RedisDB,
|
|
|
|
})
|
|
|
|
|
2024-01-01 12:50:36 +00:00
|
|
|
status := rdb.Ping(ctx)
|
|
|
|
if err := status.Err(); err != nil {
|
|
|
|
return nil, err
|
2023-12-31 12:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rdb, nil
|
|
|
|
}
|