Skip to content

Commit

Permalink
refactor: Update Redis client to use go-redis/v9 package
Browse files Browse the repository at this point in the history
  • Loading branch information
mantzas committed May 29, 2024
1 parent 8a62afa commit d26bc28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cache/redis/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -17,7 +18,7 @@ const (
)

func TestCache(t *testing.T) {
cache, err := New(Options{
cache, err := New(&redis.Options{
Addr: dsn,
Password: "", // no password set
DB: 0, // use default DB
Expand Down
15 changes: 8 additions & 7 deletions cache/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import (
"time"

"github.com/beatlabs/patron/cache"
"github.com/beatlabs/patron/client/redis"
patronredis "github.com/beatlabs/patron/client/redis"
"github.com/redis/go-redis/v9"
)

var _ cache.TTLCache = &Cache{}

// Cache encapsulates a Redis-based caching mechanism.
type Cache struct {
rdb redis.Client
rdb *redis.Client
}

// Options exposes the struct from go-redis package.
type Options redis.Options

// New creates a cache returns a new Redis client that will be used as the cache store.
func New(opt Options) (*Cache, error) {
redisDB := redis.New(redis.Options(opt))
func New(opt *redis.Options) (*Cache, error) {
redisDB, err := patronredis.New(opt)
if err != nil {
return nil, err
}
return &Cache{rdb: redisDB}, nil
}

Expand Down

0 comments on commit d26bc28

Please sign in to comment.