update atomic operation
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 17s
codeql / analyze (go) (pull_request) Failing after 52s
prbuild / test (pull_request) Failing after 5m12s
prbuild / lint (pull_request) Successful in 9m42s

This commit is contained in:
Денис Евстигнеев 2024-11-26 16:52:16 +03:00
parent 15d7ad156f
commit 9c3d0a6a6e

View File

@ -121,11 +121,9 @@ func (r *Store) Disconnect(ctx context.Context) error {
}
func (r *Store) Exists(ctx context.Context, key string, opts ...store.ExistsOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
b := r.pool.Get()
defer r.pool.Put(b)
@ -166,11 +164,9 @@ func (r *Store) Exists(ctx context.Context, key string, opts ...store.ExistsOpti
}
func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...store.ReadOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
b := r.pool.Get()
defer r.pool.Put(b)
@ -223,11 +219,9 @@ func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...s
}
func (r *Store) MRead(ctx context.Context, keys []string, vals interface{}, opts ...store.ReadOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
options := store.NewReadOptions(opts...)
@ -328,11 +322,9 @@ func (r *Store) MRead(ctx context.Context, keys []string, vals interface{}, opts
}
func (r *Store) MDelete(ctx context.Context, keys []string, opts ...store.DeleteOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
options := store.NewDeleteOptions(opts...)
@ -389,11 +381,9 @@ func (r *Store) MDelete(ctx context.Context, keys []string, opts ...store.Delete
}
func (r *Store) Delete(ctx context.Context, key string, opts ...store.DeleteOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
b := r.pool.Get()
defer r.pool.Put(b)
@ -433,11 +423,9 @@ func (r *Store) Delete(ctx context.Context, key string, opts ...store.DeleteOpti
}
func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, opts ...store.WriteOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
options := store.NewWriteOptions(opts...)
@ -522,11 +510,9 @@ func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, o
}
func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...store.WriteOption) error {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return err
}
}
b := r.pool.Get()
defer r.pool.Put(b)
@ -583,11 +569,9 @@ func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...
}
func (r *Store) List(ctx context.Context, opts ...store.ListOption) ([]string, error) {
if r.opts.LazyConnect {
if err := r.connect(ctx); err != nil {
return nil, err
}
}
b := r.pool.Get()
defer r.pool.Put(b)
@ -786,14 +770,13 @@ func (r *Store) getKey(b *strings.Builder, mainNamespace string, opNamespace str
return b.String()
}
func (r *Store) connect(ctx context.Context) error {
var err error
if r.isConnected.CompareAndSwap(0, 1) {
func (r *Store) connect(ctx context.Context) (err error) {
if r.isConnected.Load() == 0 {
if err = r.cli.Ping(ctx).Err(); err != nil {
r.isConnected.Store(0)
setSpanError(ctx, err)
}
}
return err
}
}
r.isConnected.Store(1)
return err
}