onasty/internal/store/rdb/rdb.go (view raw)
Smirnov Oleksandr
Smirnov Oleksandr
ss2316544@gmail.com feat: implement caching (#40)..., 1 year ago
ss2316544@gmail.com feat: implement caching (#40)..., 1 year ago
| 1 | package rdb |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/redis/go-redis/v9" |
| 7 | ) |
| 8 | |
| 9 | type DB struct{ *redis.Client } |
| 10 | |
| 11 | func Connect(ctx context.Context, addr, password string, db int) (*DB, error) { |
| 12 | client := redis.NewClient(&redis.Options{ //nolint:exhaustruct |
| 13 | Addr: addr, |
| 14 | Password: password, |
| 15 | DB: db, |
| 16 | }) |
| 17 | |
| 18 | _, err := client.Ping(ctx).Result() |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | |
| 23 | return &DB{Client: client}, nil |
| 24 | } |