all repos

onasty @ 643d597264b401329fd58cf48b33cfa79f2025de

a one-time notes service

onasty/internal/store/rdb/rdb.go(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package rdb

import (
	"context"

	"github.com/redis/go-redis/v9"
)

type DB struct{ *redis.Client }

func Connect(ctx context.Context, addr, password string, db int) (*DB, error) {
	client := redis.NewClient(&redis.Options{ //nolint:exhaustruct
		Addr:     addr,
		Password: password,
		DB:       db,
	})

	_, err := client.Ping(ctx).Result()
	if err != nil {
		return nil, err
	}

	return &DB{Client: client}, nil
}