Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 5, 2023
1 parent f3dac0e commit 66149e6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ func NewWithCodec(ctx context.Context, endpoints []string, options *Config, code
}

func newRedis(ctx context.Context, endpoints []string, options *Config, codec Codec) (*Store, error) {
client, err := newClient(endpoints, options)
if err != nil {
return nil, err
}

return makeStore(ctx, client, codec), nil
}

func newClient(endpoints []string, options *Config) (redis.UniversalClient, error) {
if options != nil && options.Sentinel != nil {
if options.Sentinel.MasterName == "" {
return nil, ErrMasterSetMustBeProvided
Expand Down Expand Up @@ -136,14 +145,11 @@ func newRedis(ctx context.Context, endpoints []string, options *Config, codec Co
TLSConfig: options.TLS,
}

var client redis.UniversalClient
if options.Sentinel.ClusterClient {
client = redis.NewFailoverClusterClient(cfg)
} else {
client = redis.NewFailoverClient(cfg)
return redis.NewFailoverClusterClient(cfg), nil
}

return makeStore(ctx, client, codec), nil
return redis.NewFailoverClient(cfg), nil
}

if len(endpoints) > 1 {
Expand All @@ -165,7 +171,7 @@ func newRedis(ctx context.Context, endpoints []string, options *Config, codec Co
}

// TODO: use *redis.ClusterClient if we support multiple endpoints.
return makeStore(ctx, redis.NewClient(opt), codec), nil
return redis.NewClient(opt), nil
}

func makeStore(ctx context.Context, client redis.UniversalClient, codec Codec) *Store {
Expand Down

0 comments on commit 66149e6

Please sign in to comment.