32 lines
481 B
Go
32 lines
481 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
const (
|
|
NostrDb = iota
|
|
LndDb = iota
|
|
)
|
|
|
|
type Redis struct {
|
|
Client *redis.Client
|
|
}
|
|
|
|
func New(address string, password string, database int) (*Redis, error) {
|
|
client := redis.NewClient(&redis.Options{
|
|
Addr: address,
|
|
Password: password,
|
|
DB: database,
|
|
})
|
|
ctx := context.TODO()
|
|
if err := client.Ping(ctx).Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return &Redis{
|
|
Client: client,
|
|
}, nil
|
|
}
|