Skip to content

Commit

Permalink
fix(redis/go-redis): return error if no addresses given
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 24, 2024
1 parent 08ca116 commit 6d48057
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion go-redis/go-redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Redis struct {
// Factory function create new Redis instance.
func Factory(redisConfiguration core.CacheProvider, logger core.Logger, stale time.Duration) (core.Storer, error) {
var options redis.UniversalOptions
options.ClientName = "souin-redis"

var hashtags string

Expand Down Expand Up @@ -74,6 +73,14 @@ func Factory(redisConfiguration core.CacheProvider, logger core.Logger, stale ti
}
}

if len(options.Addrs) == 0 {
return nil, errors.New("no redis addresses given.")
}

if options.ClientName == "" {
options.ClientName = "souin-redis"
}

cli := redis.NewUniversalClient(&options)

return &Redis{
Expand Down
2 changes: 1 addition & 1 deletion redis/caddy/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (Redis) CaddyModule() caddy.ModuleInfo {
// Provision to do the provisioning part.
func (b *Redis) Provision(ctx caddy.Context) error {
logger := ctx.Logger(b)
storer, err := redis.Factory(b.Configuration.Provider, logger.Sugar(), b.Configuration.Stale)

storer, err := redis.Factory(b.Configuration.Provider, logger.Sugar(), b.Configuration.Stale)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func Factory(redisConfiguration core.CacheProvider, logger core.Logger, stale ti
options.Dialer.Timeout = time.Second
}

if len(options.InitAddress) == 0 {
return nil, errors.New("no redis addresses given.")
}

cli, err := redis.NewClient(options)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6d48057

Please sign in to comment.