Compare commits

...

9 Commits
v3.10.18 ... v3

Author SHA1 Message Date
77fe9cbef6 fixup trace span names
Some checks failed
build / test (push) Failing after 1s
build / lint (push) Failing after 0s
codeql / analyze (go) (push) Failing after 0s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-22 16:06:59 +03:00
c59902201d add_labels (#120)
Some checks failed
codeql / analyze (go) (push) Failing after 56s
build / test (push) Failing after 4m59s
build / lint (push) Successful in 9m34s
closes #119

Reviewed-on: #120
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
2024-11-19 00:34:04 +03:00
0981f89f60 Merge pull request 'fix deps' (#118) from devstigneev/micro-store-redis:v3_1 into v3
Some checks failed
codeql / analyze (go) (push) Failing after 46s
build / test (push) Failing after 4m56s
build / lint (push) Successful in 9m31s
Reviewed-on: #118
2024-10-15 11:56:58 +03:00
332fe5f4d4 fix deps
Some checks failed
automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 8s
dependabot-automerge / automerge (pull_request) Has been skipped
codeql / analyze (go) (pull_request) Failing after 49s
prbuild / test (pull_request) Has been cancelled
prbuild / lint (pull_request) Has been cancelled
2024-10-14 18:56:37 +03:00
757fe0245b update all
Some checks failed
codeql / analyze (go) (push) Failing after 42s
build / test (push) Failing after 4m53s
build / lint (push) Successful in 9m28s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-14 17:49:38 +03:00
27eccc1ed2 fixup nil pointer assign
Some checks failed
codeql / analyze (go) (push) Failing after 41s
build / test (push) Failing after 4m52s
build / lint (push) Successful in 9m29s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-08 16:52:26 +03:00
7c641fa8ac fixup nil pointer assign
Some checks failed
codeql / analyze (go) (push) Failing after 39s
build / test (push) Failing after 4m55s
build / lint (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-08 16:47:27 +03:00
24c9f20196 toolchain go1.22.4 (#116)
Some checks failed
codeql / analyze (go) (push) Failing after 44s
build / test (push) Failing after 4m55s
build / lint (push) Successful in 9m29s
- go mod tidy
- fix version redis
- retract (
  v9.5.3 // This version was accidentally released.
) from github.com/redis/go-redis/extra/rediscmd/v9@v9.5.3

Reviewed-on: #116
Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru>
Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
2024-10-08 13:07:46 +03:00
953b5b0021 fixup default redis default local addr
Some checks failed
codeql / analyze (go) (push) Failing after 37s
build / test (push) Failing after 4m54s
build / lint (push) Successful in 9m29s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-06 18:49:50 +03:00
7 changed files with 96 additions and 102 deletions

17
go.mod
View File

@ -1,24 +1,19 @@
module go.unistack.org/micro-store-redis/v3
go 1.21
go 1.22
toolchain go1.22.4
require (
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.3
github.com/redis/go-redis/v9 v9.6.1
go.unistack.org/micro/v3 v3.10.95
github.com/redis/go-redis/extra/rediscmd/v9 v9.6.2
github.com/redis/go-redis/v9 v9.6.2
go.unistack.org/micro/v3 v3.10.97
)
require (
dario.cat/mergo v1.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect
github.com/google/go-cmp v0.6.0 // indirect
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
)

45
go.sum
View File

@ -1,45 +1,20 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.3 h1:1/BDligzCa40GTllkDnY3Y5DTHuKCONbB2JcRyIfl20=
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.3/go.mod h1:3dZmcLn3Qw6FLlWASn1g4y+YO9ycEFUOM+bhBmzLVKQ=
github.com/redis/go-redis/v9 v9.5.3 h1:fOAp1/uJG+ZtcITgZOfYFmTKPE7n4Vclj1wZFgRciUU=
github.com/redis/go-redis/v9 v9.5.3/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 h1:G/FZtUu7a6NTWl3KUHMV9jkLAh/Rvtf03NWMHaEDl+E=
github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/redis/go-redis/extra/rediscmd/v9 v9.6.2 h1:oBlErygFka9FAVfowzW7sRUfB7n31YX0aFzfaOflM3w=
github.com/redis/go-redis/extra/rediscmd/v9 v9.6.2/go.mod h1:jYLUE5tC8UsFnpSclhEjZlFLMMtHH4jTfFMnshNWkoo=
github.com/redis/go-redis/v9 v9.6.2 h1:w0uvkRbc9KpgD98zcvo5IrVUsn0lXpRMuhNgiHDJzdk=
github.com/redis/go-redis/v9 v9.6.2/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
go.unistack.org/micro/v3 v3.10.80 h1:A0zWNoM9MOcMg9gdFFgVkgbT3uSYVIINhuvumX9nP2o=
go.unistack.org/micro/v3 v3.10.80/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
go.unistack.org/micro/v3 v3.10.94 h1:t9J+vw6rNOQdEPFPeUvhyxlUyL+LEt9dTV/bjSEaxMI=
go.unistack.org/micro/v3 v3.10.94/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
go.unistack.org/micro/v3 v3.10.95 h1:KQse+ZpntbuzA8cH6Pz7CdvWYVdKzcR34gjnkDrHiso=
go.unistack.org/micro/v3 v3.10.95/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e h1:NumxXLPfHSndr3wBBdeKiVHjGVFzi9RX2HwwQke94iY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
go.unistack.org/micro/v3 v3.10.97 h1:8l7fv+i06/PjPrBBhRC/ZQkWGIOuHPg3jJN0vktYE78=
go.unistack.org/micro/v3 v3.10.97/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=

View File

@ -61,7 +61,7 @@ func NewOptions(opts ...Option) Options {
labelName, options.RedisName),
)
options.Logger = options.Logger.Clone(logger.WithCallerSkipCount(1))
options.Logger = options.Logger.Clone(logger.WithAddCallerSkipCount(1))
return options
}

View File

@ -2,6 +2,7 @@ package redis
import (
"context"
"errors"
"reflect"
"strings"
"time"
@ -118,6 +119,8 @@ func (r *Store) Exists(ctx context.Context, key string, opts ...store.ExistsOpti
b := r.pool.Get()
defer r.pool.Put(b)
options := store.NewExistsOptions(opts...)
labels := make([]string, 0, 6)
labels = append(labels, "name", options.Name, "statement", "exists")
timeout := r.opts.Timeout
if options.Timeout > 0 {
@ -132,21 +135,22 @@ func (r *Store) Exists(ctx context.Context, key string, opts ...store.ExistsOpti
rkey := r.getKey(b, r.opts.Namespace, options.Namespace, key)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Inc()
ts := time.Now()
val, err := r.cli.Exists(ctx, rkey).Result()
setSpanError(ctx, err)
te := time.Since(ts)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, "name", options.Name).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, "name", options.Name).Update(te.Seconds())
if err == goredis.Nil || (err == nil && val == 0) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "miss").Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, labels...).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, labels...).Update(te.Seconds())
if errors.Is(err, goredis.Nil) || (err == nil && val == 0) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "miss")...).Inc()
return store.ErrNotFound
} else if err == nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "hit").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "hit")...).Inc()
} else if err != nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "failure").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "failure")...).Inc()
return err
}
@ -158,6 +162,8 @@ func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...s
defer r.pool.Put(b)
options := store.NewReadOptions(opts...)
labels := make([]string, 0, 6)
labels = append(labels, "name", options.Name, "statement", "read")
timeout := r.opts.Timeout
if options.Timeout > 0 {
@ -172,21 +178,21 @@ func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...s
rkey := r.getKey(b, r.opts.Namespace, options.Namespace, key)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Inc()
ts := time.Now()
buf, err := r.cli.Get(ctx, rkey).Bytes()
setSpanError(ctx, err)
te := time.Since(ts)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, "name", options.Name).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, "name", options.Name).Update(te.Seconds())
if err == goredis.Nil || (err == nil && buf == nil) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "miss").Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, labels...).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, labels...).Update(te.Seconds())
if errors.Is(err, goredis.Nil) || (err == nil && buf == nil) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "miss")...).Inc()
return store.ErrNotFound
} else if err == nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "hit").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "hit")...).Inc()
} else if err != nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "failure").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "failure")...).Inc()
return err
}
@ -363,6 +369,8 @@ func (r *Store) Delete(ctx context.Context, key string, opts ...store.DeleteOpti
defer r.pool.Put(b)
options := store.NewDeleteOptions(opts...)
labels := make([]string, 0, 6)
labels = append(labels, "name", options.Name, "statement", "delete")
timeout := r.opts.Timeout
if options.Timeout > 0 {
@ -375,21 +383,22 @@ func (r *Store) Delete(ctx context.Context, key string, opts ...store.DeleteOpti
defer cancel()
}
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Inc()
ts := time.Now()
err := r.cli.Del(ctx, r.getKey(b, r.opts.Namespace, options.Namespace, key)).Err()
te := time.Since(ts)
setSpanError(ctx, err)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, "name", options.Name).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, "name", options.Name).Update(te.Seconds())
if err == goredis.Nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "miss").Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, labels...).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, labels...).Update(te.Seconds())
if errors.Is(err, goredis.Nil) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "miss")...).Inc()
return store.ErrNotFound
} else if err == nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "hit").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "hit")...).Inc()
} else if err != nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "failure").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "failure")...).Inc()
return err
}
@ -484,6 +493,8 @@ func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...
defer r.pool.Put(b)
options := store.NewWriteOptions(opts...)
labels := make([]string, 0, 6)
labels = append(labels, "name", options.Name, "statement", "write")
timeout := r.opts.Timeout
if options.Timeout > 0 {
@ -512,22 +523,22 @@ func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...
}
}
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Inc()
ts := time.Now()
err := r.cli.Set(ctx, rkey, buf, options.TTL).Err()
te := time.Since(ts)
setSpanError(ctx, err)
r.opts.Meter.Counter(semconv.StoreRequestInflight, "name", options.Name).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, "name", options.Name).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, "name", options.Name).Update(te.Seconds())
if err == goredis.Nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "miss").Inc()
r.opts.Meter.Counter(semconv.StoreRequestInflight, labels...).Dec()
r.opts.Meter.Summary(semconv.StoreRequestLatencyMicroseconds, labels...).Update(te.Seconds())
r.opts.Meter.Histogram(semconv.StoreRequestDurationSeconds, labels...).Update(te.Seconds())
if errors.Is(err, goredis.Nil) {
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "miss")...).Inc()
return store.ErrNotFound
} else if err == nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "hit").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "hit")...).Inc()
} else if err != nil {
r.opts.Meter.Counter(semconv.StoreRequestTotal, "name", options.Name, "status", "failure").Inc()
r.opts.Meter.Counter(semconv.StoreRequestTotal, append(labels, "status", "failure")...).Inc()
return err
}
@ -625,12 +636,12 @@ func NewStore(opts ...store.Option) *Store {
}
func (r *Store) configure() error {
var universalOptions *goredis.UniversalOptions
if r.cli != nil && r.opts.Context == nil {
return nil
}
universalOptions := DefaultUniversalOptions
if r.opts.Context != nil {
if o, ok := r.opts.Context.Value(configKey{}).(*goredis.Options); ok {
universalOptions.Addrs = []string{o.Addr}
@ -704,14 +715,10 @@ func (r *Store) configure() error {
}
}
if universalOptions == nil {
universalOptions = DefaultUniversalOptions
}
if len(r.opts.Addrs) > 0 {
universalOptions.Addrs = r.opts.Addrs
} else {
universalOptions.Addrs = []string{"redis://127.0.0.1:6379"}
universalOptions.Addrs = []string{"127.0.0.1:6379"}
}
r.cli = goredis.NewUniversalClient(universalOptions)

View File

@ -12,6 +12,26 @@ import (
"go.unistack.org/micro/v3/tracer"
)
func TestLazyConnect(t *testing.T) {
ctx := context.Background()
var err error
r := NewStore()
if err = r.Init(); err != nil {
t.Fatal(err)
}
if err = r.Connect(ctx); err != nil {
t.Logf("connect failed %v", err)
}
for {
if err = r.Write(ctx, "mykey", "myval"); err != nil {
t.Logf("failed to write %v", err)
}
}
}
func TestKeepTTL(t *testing.T) {
ctx := context.Background()

View File

@ -33,20 +33,17 @@ func (r *Store) statsMeter() {
ticker := time.NewTicker(meter.DefaultMeterStatsInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if st == nil {
return
}
stats := st.PoolStats()
r.opts.Meter.Counter(PoolHitsTotal).Set(uint64(stats.Hits))
r.opts.Meter.Counter(PoolMissesTotal).Set(uint64(stats.Misses))
r.opts.Meter.Counter(PoolTimeoutTotal).Set(uint64(stats.Timeouts))
r.opts.Meter.Counter(PoolConnTotalCurrent).Set(uint64(stats.TotalConns))
r.opts.Meter.Counter(PoolConnIdleCurrent).Set(uint64(stats.IdleConns))
r.opts.Meter.Counter(PoolConnStaleTotal).Set(uint64(stats.StaleConns))
for _ = range ticker.C {
if st == nil {
return
}
stats := st.PoolStats()
r.opts.Meter.Counter(PoolHitsTotal).Set(uint64(stats.Hits))
r.opts.Meter.Counter(PoolMissesTotal).Set(uint64(stats.Misses))
r.opts.Meter.Counter(PoolTimeoutTotal).Set(uint64(stats.Timeouts))
r.opts.Meter.Counter(PoolConnTotalCurrent).Set(uint64(stats.TotalConns))
r.opts.Meter.Counter(PoolConnIdleCurrent).Set(uint64(stats.IdleConns))
r.opts.Meter.Counter(PoolConnStaleTotal).Set(uint64(stats.StaleConns))
}
}()
}

View File

@ -73,7 +73,7 @@ func (h *tracingHook) ProcessHook(hook goredis.ProcessHook) goredis.ProcessHook
case "cluster slots":
break
default:
_, span := h.tr.Start(ctx, "goredis.process", append(h.opts, tracer.WithSpanLabels("db.statement", cmdString))...)
_, span := h.tr.Start(ctx, "sdk.database", append(h.opts, tracer.WithSpanLabels("db.statement", cmdString))...)
defer func() {
recordError(span, err)
span.Finish()
@ -91,11 +91,11 @@ func (h *tracingHook) ProcessPipelineHook(hook goredis.ProcessPipelineHook) gore
_, cmdsString := rediscmd.CmdsString(cmds)
opts := append(h.opts, tracer.WithSpanLabels(
"db.goredis.num_cmd", strconv.Itoa(len(cmds)),
"db.database.num_cmd", strconv.Itoa(len(cmds)),
"db.statement", cmdsString,
))
_, span := h.tr.Start(ctx, "goredis.process_pipeline", opts...)
_, span := h.tr.Start(ctx, "sdk.database", opts...)
defer span.Finish()
err := hook(ctx, cmds)