Merge pull request 'fixup tls redis options' (#125) from tlsfix into v3

Reviewed-on: #125
This commit is contained in:
Василий Толстов 2024-12-05 13:06:16 +03:00
commit 965a9f1b8e

View File

@ -98,11 +98,7 @@ func (r *Store) Connect(ctx context.Context) error {
} }
func (r *Store) Init(opts ...store.Option) error { func (r *Store) Init(opts ...store.Option) error {
for _, o := range opts { err := r.configure(opts...)
o(&r.opts)
}
err := r.configure()
if err != nil { if err != nil {
return err return err
} }
@ -675,11 +671,15 @@ func NewStore(opts ...store.Option) *Store {
} }
} }
func (r *Store) configure() error { func (r *Store) configure(opts ...store.Option) error {
if r.cli != nil && r.opts.Context == nil { if r.cli != nil && len(opts) == 0 {
return nil return nil
} }
for _, o := range opts {
o(&r.opts)
}
universalOptions := DefaultUniversalOptions universalOptions := DefaultUniversalOptions
if r.opts.Context != nil { if r.opts.Context != nil {
@ -708,8 +708,8 @@ func (r *Store) configure() error {
universalOptions.ConnMaxIdleTime = o.ConnMaxIdleTime universalOptions.ConnMaxIdleTime = o.ConnMaxIdleTime
universalOptions.ConnMaxLifetime = o.ConnMaxLifetime universalOptions.ConnMaxLifetime = o.ConnMaxLifetime
if r.opts.TLSConfig != nil { if o.TLSConfig != nil {
universalOptions.TLSConfig = r.opts.TLSConfig universalOptions.TLSConfig = o.TLSConfig
} }
} }
@ -742,15 +742,15 @@ func (r *Store) configure() error {
universalOptions.MaxIdleConns = o.MaxIdleConns universalOptions.MaxIdleConns = o.MaxIdleConns
universalOptions.ConnMaxIdleTime = o.ConnMaxIdleTime universalOptions.ConnMaxIdleTime = o.ConnMaxIdleTime
universalOptions.ConnMaxLifetime = o.ConnMaxLifetime universalOptions.ConnMaxLifetime = o.ConnMaxLifetime
if r.opts.TLSConfig != nil { if o.TLSConfig != nil {
universalOptions.TLSConfig = r.opts.TLSConfig universalOptions.TLSConfig = o.TLSConfig
} }
} }
if o, ok := r.opts.Context.Value(universalConfigKey{}).(*goredis.UniversalOptions); ok { if o, ok := r.opts.Context.Value(universalConfigKey{}).(*goredis.UniversalOptions); ok {
universalOptions = o universalOptions = o
if r.opts.TLSConfig != nil { if o.TLSConfig != nil {
universalOptions.TLSConfig = r.opts.TLSConfig universalOptions.TLSConfig = o.TLSConfig
} }
} }
} }