Skip to content

Commit

Permalink
PLAT-2247 Update redis driver to be redis v7 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
radykal-com committed Jul 9, 2024
1 parent 74046f3 commit fe6f058
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 167 deletions.
63 changes: 30 additions & 33 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ const (
BackendMemory = "memory"
BackendRedis = "redis"

RedisModeRedis = "redis"
RedisModeCluster = "rediscluster"
RedisDefaultDialTimeout = 100 * time.Millisecond
RedisDefaultReadTimeout = 100 * time.Millisecond
RedisDefaultWriteTimeout = 200 * time.Millisecond
RedisDefaultMaxRetries = 0
RedisDefaultIdleTimeout = 5 * time.Minute
RedisDefaultIdleCheckFrequency = 1 * time.Minute
RedisDefaultPoolSize = 10
RedisDefaultPoolTimeout = 10 * time.Millisecond
RedisDefaultTtl = 1 * time.Hour
RedisModeRedis = "redis"
RedisModeCluster = "rediscluster"
RedisDefaultDialTimeout = 100 * time.Millisecond
RedisDefaultReadTimeout = 100 * time.Millisecond
RedisDefaultWriteTimeout = 200 * time.Millisecond
RedisDefaultMaxRetries = 0
RedisDefaultIdleTimeout = 5 * time.Minute
RedisDefaultPoolSize = 10
RedisDefaultPoolTimeout = 10 * time.Millisecond
RedisDefaultTtl = 1 * time.Hour
)

var ErrMissingRequired = func(field string) error {
Expand All @@ -34,17 +33,16 @@ var ErrInvalidValue = func(field string) error {
}

type RedisConfig struct {
Mode string `mapstructure:"mode"`
Address string `mapstructure:"address"`
DialTimeout time.Duration `mapstructure:"dialTimeout"`
ReadTimeout time.Duration `mapstructure:"readTimeout"`
WriteTimeout time.Duration `mapstructure:"writeTimeout"`
MaxRetries int `mapstructure:"maxRetries"`
IdleTimeout time.Duration `mapstructure:"idleTimeout"`
IdleCheckFrequency time.Duration `mapstructure:"idleCheckFrequency"`
PoolSize int `mapstructure:"poolSize"`
PoolTimeout time.Duration `mapstructure:"poolTimeout"`
Ttl time.Duration `mapstructure:"ttl"`
Mode string `mapstructure:"mode"`
Address string `mapstructure:"address"`
DialTimeout time.Duration `mapstructure:"dialTimeout"`
ReadTimeout time.Duration `mapstructure:"readTimeout"`
WriteTimeout time.Duration `mapstructure:"writeTimeout"`
MaxRetries int `mapstructure:"maxRetries"`
IdleTimeout time.Duration `mapstructure:"idleTimeout"`
PoolSize int `mapstructure:"poolSize"`
PoolTimeout time.Duration `mapstructure:"poolTimeout"`
Ttl time.Duration `mapstructure:"ttl"`
}

type Config struct {
Expand All @@ -61,17 +59,16 @@ func ConfigGetter(cfg *config.Backend) (*Config, error) {

var cacheConfig = Config{
RedisConfig: RedisConfig{
Mode: "",
Address: "",
DialTimeout: RedisDefaultDialTimeout,
ReadTimeout: RedisDefaultReadTimeout,
WriteTimeout: RedisDefaultWriteTimeout,
MaxRetries: RedisDefaultMaxRetries,
IdleTimeout: RedisDefaultIdleTimeout,
IdleCheckFrequency: RedisDefaultIdleCheckFrequency,
PoolSize: RedisDefaultPoolSize,
PoolTimeout: RedisDefaultPoolTimeout,
Ttl: RedisDefaultTtl,
Mode: "",
Address: "",
DialTimeout: RedisDefaultDialTimeout,
ReadTimeout: RedisDefaultReadTimeout,
WriteTimeout: RedisDefaultWriteTimeout,
MaxRetries: RedisDefaultMaxRetries,
IdleTimeout: RedisDefaultIdleTimeout,
PoolSize: RedisDefaultPoolSize,
PoolTimeout: RedisDefaultPoolTimeout,
Ttl: RedisDefaultTtl,
},
}
d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Expand Down
25 changes: 10 additions & 15 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestConfig_ok(t *testing.T) {
assert.Equal(t, httpcache.RedisDefaultWriteTimeout, rc.WriteTimeout)
assert.Equal(t, httpcache.RedisDefaultMaxRetries, rc.MaxRetries)
assert.Equal(t, httpcache.RedisDefaultIdleTimeout, rc.IdleTimeout)
assert.Equal(t, httpcache.RedisDefaultIdleCheckFrequency, rc.IdleCheckFrequency)
assert.Equal(t, httpcache.RedisDefaultPoolSize, rc.PoolSize)
assert.Equal(t, httpcache.RedisDefaultPoolTimeout, rc.PoolTimeout)
assert.Equal(t, httpcache.RedisDefaultTtl, rc.Ttl)
Expand All @@ -79,7 +78,6 @@ func TestConfig_ok(t *testing.T) {
wt := "25us"
mr := 666
it := "99s"
icf := "14ms"
ps := 77
pt := "878s"
ttl := "65432s"
Expand All @@ -89,17 +87,16 @@ func TestConfig_ok(t *testing.T) {
httpcache.Namespace: map[string]interface{}{
"type": "redis",
"redis": map[string]interface{}{
"address": address,
"mode": mode,
"dialTimeout": dt,
"readTimeout": rt,
"writeTimeout": wt,
"maxRetries": mr,
"idleTimeout": it,
"idleCheckFrequency": icf,
"poolSize": ps,
"poolTimeout": pt,
"ttl": ttl,
"address": address,
"mode": mode,
"dialTimeout": dt,
"readTimeout": rt,
"writeTimeout": wt,
"maxRetries": mr,
"idleTimeout": it,
"poolSize": ps,
"poolTimeout": pt,
"ttl": ttl,
},
},
},
Expand All @@ -121,8 +118,6 @@ func TestConfig_ok(t *testing.T) {
assert.Equal(t, mr, rc.MaxRetries)
exIt, _ := time.ParseDuration(it)
assert.Equal(t, exIt, rc.IdleTimeout)
exIcf, _ := time.ParseDuration(icf)
assert.Equal(t, exIcf, rc.IdleCheckFrequency)
assert.Equal(t, ps, rc.PoolSize)
exPt, _ := time.ParseDuration(pt)
assert.Equal(t, exPt, rc.PoolTimeout)
Expand Down
53 changes: 29 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,46 @@ module github.com/krakendio/krakend-httpcache/v2
go 1.20

require (
github.com/go-redis/redis/v8 v8.11.5
github.com/golang/mock v1.4.4
github.com/krakendio/httpcache v0.0.0-20221129153752-65a87a5c2bc5
github.com/luraproject/lura/v2 v2.6.1
github.com/mitchellh/mapstructure v1.5.0
github.com/stretchr/testify v1.8.1
gopkg.in/DataDog/dd-trace-go.v1 v1.42.1
github.com/redis/go-redis/v9 v9.5.2
github.com/stretchr/testify v1.8.4
go.uber.org/mock v0.4.0
gopkg.in/DataDog/dd-trace-go.v1 v1.65.1
)

require (
github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 // indirect
github.com/DataDog/datadog-go v4.8.2+incompatible // indirect
github.com/DataDog/datadog-go/v5 v5.0.2 // indirect
github.com/DataDog/sketches-go v1.2.1 // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/DataDog/appsec-internal-go v1.6.0 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.48.0 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.1 // indirect
github.com/DataDog/datadog-go/v5 v5.3.0 // indirect
github.com/DataDog/go-libddwaf/v3 v3.2.1 // indirect
github.com/DataDog/go-tuf v1.0.2-0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.6.0-alpha.5 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/krakendio/flatmap v1.1.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/philhofer/fwd v1.1.1 // indirect
github.com/outcaste-io/ristretto v0.2.3 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tinylib/msgp v1.1.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
golang.org/x/sys v0.15.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading

0 comments on commit fe6f058

Please sign in to comment.