37 lines
724 B
Go
37 lines
724 B
Go
package cache
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
|
|
"gitea.local/admin/hspguard/internal/config"
|
|
"github.com/redis/go-redis/v9"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
type Client struct {
|
|
rClient *redis.Client
|
|
}
|
|
|
|
func NewClient(cfg *config.AppConfig) *Client {
|
|
opts, err := redis.ParseURL(cfg.RedisURL)
|
|
if err != nil {
|
|
log.Fatalln("ERR: Failed to get redis options:", err)
|
|
return nil
|
|
}
|
|
|
|
client := redis.NewClient(opts)
|
|
|
|
return &Client{
|
|
rClient: client,
|
|
}
|
|
}
|
|
|
|
func (c *Client) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd {
|
|
return c.rClient.Set(ctx, key, value, expiration)
|
|
}
|
|
|
|
func (c *Client) Get(ctx context.Context, key string) *redis.StringCmd {
|
|
return c.rClient.Get(ctx, key)
|
|
}
|