well-goknown/redis/redis.go
2023-12-31 20:09:37 -05:00

39 lines
599 B
Go

package redis
import (
"context"
"github.com/redis/go-redis/v9"
)
const (
NostrKeyspace = iota
LndKeyspace = iota
LnurlpKeyspace = iota
)
type Redis struct {
Client *redis.Client
}
var (
NostrRedisConn *Redis
LndRedisConn *Redis
LnurlpRedisConn *Redis
)
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
}