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
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:
parent
15d7ad156f
commit
9c3d0a6a6e
57
redis.go
57
redis.go
@ -121,10 +121,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b := r.pool.Get()
|
||||
@ -166,10 +164,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b := r.pool.Get()
|
||||
@ -223,10 +219,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := store.NewReadOptions(opts...)
|
||||
@ -328,10 +322,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := store.NewDeleteOptions(opts...)
|
||||
@ -389,10 +381,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b := r.pool.Get()
|
||||
@ -433,10 +423,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := store.NewWriteOptions(opts...)
|
||||
@ -522,10 +510,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b := r.pool.Get()
|
||||
@ -583,10 +569,8 @@ 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
|
||||
}
|
||||
if err := r.connect(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b := r.pool.Get()
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user