well-goknown/redis/redis.go

37 lines
548 B
Go
Raw Normal View History

2023-02-03 04:56:15 +00:00
package redis
2023-02-05 02:07:26 +00:00
import (
"context"
"github.com/redis/go-redis/v9"
)
2023-02-03 04:56:15 +00:00
2023-02-04 05:32:25 +00:00
const (
2023-05-01 22:41:28 +00:00
NostrKeyspace = iota
LndKeyspace = iota
2023-02-04 05:32:25 +00:00
)
2023-02-03 04:56:15 +00:00
type Redis struct {
Client *redis.Client
}
2023-05-01 22:41:28 +00:00
var (
NostrRedisConn *Redis
LndRedisConn *Redis
)
2023-02-03 04:56:15 +00:00
func New(address string, password string, database int) (*Redis, error) {
client := redis.NewClient(&redis.Options{
Addr: address,
Password: password,
DB: database,
})
2023-02-05 02:07:26 +00:00
ctx := context.TODO()
if err := client.Ping(ctx).Err(); err != nil {
2023-02-03 04:56:15 +00:00
return nil, err
}
return &Redis{
Client: client,
}, nil
}