41 lines
616 B
Go
41 lines
616 B
Go
// Path: Backend/internal/cache/valkey.go
|
|
|
|
package cache
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
type Client struct {
|
|
Redis *redis.Client
|
|
}
|
|
|
|
func NewValkey(valkeyURL string) (*Client, error) {
|
|
options, err := redis.ParseURL(valkeyURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
client := redis.NewClient(options)
|
|
|
|
return &Client{Redis: client}, nil
|
|
}
|
|
|
|
func (c *Client) Health(ctx context.Context) error {
|
|
if c == nil || c.Redis == nil {
|
|
return nil
|
|
}
|
|
|
|
return c.Redis.Ping(ctx).Err()
|
|
}
|
|
|
|
func (c *Client) Close() error {
|
|
if c == nil || c.Redis == nil {
|
|
return nil
|
|
}
|
|
|
|
return c.Redis.Close()
|
|
}
|