diff --git a/go.mod b/go.mod index 86cf23c..5cd0226 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,23 @@ module go.unistack.org/micro-store-redis/v4 -go 1.20 +go 1.22.0 + +toolchain go1.24.2 require ( - github.com/redis/go-redis/v9 v9.2.1 - go.unistack.org/micro/v4 v4.0.7 + github.com/redis/go-redis/v9 v9.7.3 + go.unistack.org/micro/v4 v4.1.6 ) require ( - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/ash3in/uuidv8 v1.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/matoous/go-nanoid v1.5.1 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect + github.com/spf13/cast v1.7.1 // indirect + go.unistack.org/micro-proto/v4 v4.1.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f30879b..b58873d 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,33 @@ +github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI= +github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= 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/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4= +github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg= github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM= +github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA= +github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= +github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk= +go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec= go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM= go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk= +go.unistack.org/micro/v4 v4.1.6 h1:sYLpe1Vd8/lDwddtV0BLTvJ+i+fllXAS4fZngT1wKZ4= +go.unistack.org/micro/v4 v4.1.6/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/options.go b/options.go index 86751e1..be1314c 100644 --- a/options.go +++ b/options.go @@ -2,11 +2,11 @@ package redis import ( "github.com/redis/go-redis/v9" - "go.unistack.org/micro/v4/options" + "go.unistack.org/micro/v4/store" ) type universalConfigKey struct{} -func UniversalConfig(c *redis.UniversalOptions) options.Option { - return options.ContextOption(universalConfigKey{}, c) +func UniversalConfig(c *redis.UniversalOptions) store.Option { + return store.SetOption(universalConfigKey{}, c) } diff --git a/redis.go b/redis.go index 9077bc6..71df9db 100755 --- a/redis.go +++ b/redis.go @@ -33,7 +33,7 @@ func (r *Store) Disconnect(ctx context.Context) error { return r.cli.Close() } -func (r *Store) Exists(ctx context.Context, key string, opts ...options.Option) error { +func (r *Store) Exists(ctx context.Context, key string, opts ...store.ExistsOption) error { if r.opts.Timeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, r.opts.Timeout) @@ -56,7 +56,7 @@ func (r *Store) Exists(ctx context.Context, key string, opts ...options.Option) return nil } -func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error { +func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...store.ReadOption) error { if r.opts.Timeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, r.opts.Timeout) @@ -82,7 +82,7 @@ func (r *Store) Read(ctx context.Context, key string, val interface{}, opts ...o return r.opts.Codec.Unmarshal(buf, val) } -func (r *Store) MRead(ctx context.Context, keys []string, vals interface{}, opts ...options.Option) error { +func (r *Store) MRead(ctx context.Context, keys []string, vals interface{}, opts ...store.ReadOption) error { if len(keys) == 1 { vt := reflect.ValueOf(vals) if vt.Kind() == reflect.Ptr { @@ -157,7 +157,7 @@ func (r *Store) MRead(ctx context.Context, keys []string, vals interface{}, opts return nil } -func (r *Store) MDelete(ctx context.Context, keys []string, opts ...options.Option) error { +func (r *Store) MDelete(ctx context.Context, keys []string, opts ...store.DeleteOption) error { if len(keys) == 1 { return r.Delete(ctx, keys[0], opts...) } @@ -179,7 +179,7 @@ func (r *Store) MDelete(ctx context.Context, keys []string, opts ...options.Opti return r.cli.Del(ctx, keys...).Err() } -func (r *Store) Delete(ctx context.Context, key string, opts ...options.Option) error { +func (r *Store) Delete(ctx context.Context, key string, opts ...store.DeleteOption) error { if r.opts.Timeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, r.opts.Timeout) @@ -195,7 +195,7 @@ func (r *Store) Delete(ctx context.Context, key string, opts ...options.Option) return r.cli.Del(ctx, fmt.Sprintf("%s%s", options.Namespace, key)).Err() } -func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, opts ...options.Option) error { +func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, opts ...store.WriteOption) error { if len(keys) == 1 { return r.Write(ctx, keys[0], vals[0], opts...) } @@ -254,7 +254,7 @@ func (r *Store) MWrite(ctx context.Context, keys []string, vals []interface{}, o return nil } -func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error { +func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ...store.WriteOption) error { if r.opts.Timeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, r.opts.Timeout) @@ -287,7 +287,7 @@ func (r *Store) Write(ctx context.Context, key string, val interface{}, opts ... return r.cli.Set(ctx, key, buf, options.TTL).Err() } -func (r *Store) List(ctx context.Context, opts ...options.Option) ([]string, error) { +func (r *Store) List(ctx context.Context, opts ...store.ListOption) ([]string, error) { options := store.NewListOptions(opts...) if len(options.Namespace) == 0 { options.Namespace = r.opts.Namespace @@ -330,7 +330,7 @@ func (r *Store) String() string { return "redis" } -func NewStore(opts ...options.Option) *Store { +func NewStore(opts ...store.Option) *Store { return &Store{opts: store.NewOptions(opts...)} } @@ -377,8 +377,8 @@ func (r *Store) configure(opts ...options.Option) error { } } - if len(r.opts.Address) > 0 { - redisUniversalOptions.Addrs = r.opts.Address + if len(r.opts.Addrs) > 0 { + redisUniversalOptions.Addrs = r.opts.Addrs } else if len(redisUniversalOptions.Addrs) == 0 { redisUniversalOptions.Addrs = []string{"redis://127.0.0.1:6379"} } diff --git a/redis_test.go b/redis_test.go index e961808..93b4b80 100755 --- a/redis_test.go +++ b/redis_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/redis/go-redis/v9" - "go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/store" ) @@ -38,7 +37,7 @@ func Test_rkv_configure(t *testing.T) { }, }, { - name: "legacy Url", fields: fields{options: store.Options{Address: []string{"127.0.0.1:6379"}}, Client: nil}, + name: "legacy Url", fields: fields{options: store.Options{Addrs: []string{"127.0.0.1:6379"}}, Client: nil}, wantErr: false, want: wantValues{ username: "", password: "", @@ -46,7 +45,7 @@ func Test_rkv_configure(t *testing.T) { }, }, { - name: "New Url", fields: fields{options: store.Options{Address: []string{"redis://127.0.0.1:6379"}}, Client: nil}, + name: "New Url", fields: fields{options: store.Options{Addrs: []string{"redis://127.0.0.1:6379"}}, Client: nil}, wantErr: false, want: wantValues{ username: "", password: "", @@ -54,7 +53,7 @@ func Test_rkv_configure(t *testing.T) { }, }, { - name: "Url with Pwd", fields: fields{options: store.Options{Address: []string{"redis://:password@redis:6379"}}, Client: nil}, + name: "Url with Pwd", fields: fields{options: store.Options{Addrs: []string{"redis://:password@redis:6379"}}, Client: nil}, wantErr: false, want: wantValues{ username: "", password: "password", @@ -62,7 +61,7 @@ func Test_rkv_configure(t *testing.T) { }, }, { - name: "Url with username and Pwd", fields: fields{options: store.Options{Address: []string{"redis://username:password@redis:6379"}}, Client: nil}, + name: "Url with username and Pwd", fields: fields{options: store.Options{Addrs: []string{"redis://username:password@redis:6379"}}, Client: nil}, wantErr: false, want: wantValues{ username: "username", password: "password", @@ -91,7 +90,7 @@ func Test_Store(t *testing.T) { if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 { t.Skip() } - r := NewStore(options.Address(os.Getenv("STORE_NODES"))) + r := NewStore(store.Addrs(os.Getenv("STORE_NODES"))) if err := r.Init(); err != nil { t.Fatal(err) @@ -131,7 +130,7 @@ func Test_MRead(t *testing.T) { if tr := os.Getenv("INTEGRATION_TESTS"); len(tr) > 0 { t.Skip() } - r := NewStore(options.Address(os.Getenv("STORE_NODES"))) + r := NewStore(store.Addrs(os.Getenv("STORE_NODES"))) if err = r.Init(); err != nil { t.Fatal(err)