diff --git a/clients/cache/redis.go b/clients/cache/redis.go index b400a30..16da45a 100644 --- a/clients/cache/redis.go +++ b/clients/cache/redis.go @@ -2,45 +2,39 @@ package cache import ( "context" - "fmt" "time" "github.com/kava-labs/kava-proxy-service/logging" "github.com/redis/go-redis/v9" ) +type RedisConfig struct { + Address string + Password string + DB int +} + // RedisCache is an implementation of Cache that uses Redis as the caching backend. type RedisCache struct { client *redis.Client - logger *logging.ServiceLogger + *logging.ServiceLogger } var _ Cache = (*RedisCache)(nil) func NewRedisCache( - ctx context.Context, + cfg *RedisConfig, logger *logging.ServiceLogger, - address string, - password string, - db int, ) (*RedisCache, error) { client := redis.NewClient(&redis.Options{ - Addr: address, - Password: password, - DB: db, + Addr: cfg.Address, + Password: cfg.Password, + DB: cfg.DB, }) - // Check if we can connect to Redis - _, err := client.Ping(ctx).Result() - if err != nil { - return nil, fmt.Errorf("error connecting to Redis: %v", err) - } - - logger.Logger.Debug().Msg("connected to Redis") - return &RedisCache{ - client: client, - logger: logger, + client: client, + ServiceLogger: logger, }, nil }