Skip to content

Commit

Permalink
CR's fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Oct 10, 2023
1 parent ddb954f commit da77cd4
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions clients/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit da77cd4

Please sign in to comment.