feat: redis configuration & client

This commit is contained in:
2025-06-07 01:32:22 +02:00
parent 6666b20464
commit 8902f4d187
4 changed files with 46 additions and 3 deletions

36
internal/cache/mod.go vendored Normal file
View File

@ -0,0 +1,36 @@
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)
}

View File

@ -14,6 +14,7 @@ type AppConfig struct {
Host string `env:"GUARD_HOST" default:"127.0.0.1"`
Uri string `env:"GUARD_URI" default:"http://127.0.0.1:3001"`
DatabaseURL string `env:"GUARD_DB_URL" required:"true"`
RedisURL string `env:"GUARD_REDIS_URL" default:"redis://localhost:6379/0"`
Admin AdminConfig
Jwt JwtConfig
Minio MinioConfig