Merge branch 'master' into master
Some checks failed
automerge / automerge (pull_request) Failing after 15s
autoapprove / autoapprove (pull_request) Failing after 2m0s
lint / lint (pull_request) Successful in 4m52s
dependabot-automerge / automerge (pull_request) Failing after 14m56s
test / test (pull_request) Successful in 17m34s

This commit is contained in:
Василий Толстов 2024-12-15 22:10:20 +03:00
commit 54cb7188b8

View File

@ -22,11 +22,7 @@ func (r *Store) Connect(ctx context.Context) error {
} }
func (r *Store) Init(opts ...options.Option) error { func (r *Store) Init(opts ...options.Option) error {
for _, o := range opts { return r.configure(opts...)
o(&r.opts)
}
return r.configure()
} }
func (r *Store) Redis() redis.UniversalClient { func (r *Store) Redis() redis.UniversalClient {
@ -237,8 +233,11 @@ func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, o
} }
cmds, err := r.cli.Pipelined(ctx, func(pipe redis.Pipeliner) error { cmds, err := r.cli.Pipelined(ctx, func(pipe redis.Pipeliner) error {
var err error
for idx := 0; idx < len(kvs); idx += 2 { for idx := 0; idx < len(kvs); idx += 2 {
pipe.Set(ctx, kvs[idx], kvs[idx+1], options.TTL).Result() if _, err = pipe.Set(ctx, kvs[idx], kvs[idx+1], options.TTL).Result(); err != nil {
return err
}
} }
return nil return nil
}) })
@ -335,13 +334,20 @@ func NewStore(opts ...options.Option) *Store {
return &Store{opts: store.NewOptions(opts...)} return &Store{opts: store.NewOptions(opts...)}
} }
func (r *Store) configure() error { func (r *Store) configure(opts ...options.Option) error {
var redisUniversalOptions *redis.UniversalOptions if r.cli != nil && len(opts) == 0 {
if r.cli != nil && r.opts.Context == nil {
return nil return nil
} }
var redisUniversalOptions *redis.UniversalOptions
var err error
for _, o := range opts {
if err = o(r.opts); err != nil {
return err
}
}
if r.opts.Context != nil { if r.opts.Context != nil {
if c, ok := r.opts.Context.Value(universalConfigKey{}).(*redis.UniversalOptions); ok { if c, ok := r.opts.Context.Value(universalConfigKey{}).(*redis.UniversalOptions); ok {
redisUniversalOptions = c redisUniversalOptions = c