Feat: Backend scaffolding and local dev stack
This commit is contained in:
40
Backend/internal/cache/valkey.go
vendored
Normal file
40
Backend/internal/cache/valkey.go
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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()
|
||||
}
|
||||
Reference in New Issue
Block a user