chg: feat: rewrite to be a torrent indexer

This commit is contained in:
2023-09-23 17:02:55 +00:00
parent c68df1ab37
commit faa721dc19
15 changed files with 711 additions and 389 deletions

44
cache/redis.go vendored Normal file
View File

@@ -0,0 +1,44 @@
package cache
import (
"context"
"fmt"
"os"
"time"
"github.com/redis/go-redis/v9"
)
var (
DefaultExpiration = 24 * time.Hour * 180 // 180 days
IndexerComandoTorrents = "indexer:comando_torrents"
)
type Redis struct {
client *redis.Client
}
func NewRedis() *Redis {
redisHost := os.Getenv("REDIS_HOST")
if redisHost == "" {
redisHost = "localhost"
}
return &Redis{
client: redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:6379", redisHost),
Password: "",
}),
}
}
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()
}
func (r *Redis) SetWithExpiration(ctx context.Context, key string, value []byte, expiration time.Duration) error {
return r.client.Set(ctx, key, value, expiration).Err()
}