Feat/ttl config (#23)

* new: feat: add option to customize ttl

* chg: docs: add docs form ENVs
This commit is contained in:
2024-12-11 16:01:09 -03:00
committed by GitHub
parent 6c02f72e13
commit a6c3d3eed1
6 changed files with 61 additions and 12 deletions

12
cache/redis.go vendored
View File

@@ -9,13 +9,14 @@ import (
"github.com/redis/go-redis/v9"
)
var (
const (
DefaultExpiration = 24 * time.Hour * 7 // 7 days
IndexerComandoTorrents = "indexer:comando_torrents"
)
type Redis struct {
client *redis.Client
client *redis.Client
defaultExpiration time.Duration
}
func NewRedis() *Redis {
@@ -28,15 +29,20 @@ func NewRedis() *Redis {
Addr: fmt.Sprintf("%s:6379", redisHost),
Password: "",
}),
defaultExpiration: DefaultExpiration,
}
}
func (r *Redis) SetDefaultExpiration(expiration time.Duration) {
r.defaultExpiration = expiration
}
func (r *Redis) Get(ctx context.Context, key string) ([]byte, error) {
return r.client.Get(ctx, key).Bytes()
}
func (r *Redis) Set(ctx context.Context, key string, value []byte) error {
return r.client.Set(ctx, key, value, DefaultExpiration).Err()
return r.client.Set(ctx, key, value, r.defaultExpiration).Err()
}
func (r *Redis) SetWithExpiration(ctx context.Context, key string, value []byte, expiration time.Duration) error {