38 lines
1023 B
Go
38 lines
1023 B
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/tuusuario/go-sync-service/internal/domain/ports"
|
|
)
|
|
|
|
type RedisProvider struct {
|
|
ParamManager *RedisManager
|
|
Ctx context.Context
|
|
}
|
|
|
|
// UpdateParamInRedis implements ports.RedisConfigProvider.
|
|
func (p *RedisProvider) UpdateParam(key string, value string, expiration time.Duration) error {
|
|
return p.ParamManager.UpdateParam(p.Ctx, key, value, expiration)
|
|
}
|
|
|
|
func NewRedisProvider(pm *RedisManager, ctx context.Context) ports.RedisConfigProvider {
|
|
return &RedisProvider{ParamManager: pm, Ctx: ctx}
|
|
}
|
|
|
|
func (p *RedisProvider) GetString(key string) (string, error) {
|
|
return p.ParamManager.GetRawValue(p.Ctx, key)
|
|
}
|
|
|
|
// GetInt64 retrieves an int64 configuration value from Redis, given its key.
|
|
// It returns 0 and an error if the key is not found in Redis.
|
|
func (p *RedisProvider) GetInt64(key string) (int64, error) {
|
|
val, err := p.ParamManager.GetRawValue(p.Ctx, key)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return strconv.ParseInt(val, 10, 64)
|
|
}
|