From 803592d454c49277405303fa6261dc090db542d2 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 25 Apr 2021 12:16:13 +0300 Subject: [PATCH 1/5] Otel v0.20.0 --- extra/redisotel/go.mod | 4 ++-- extra/redisotel/go.sum | 7 +++++++ go.mod | 6 +++--- go.sum | 16 ++++++++-------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/extra/redisotel/go.mod b/extra/redisotel/go.mod index f514a062..9e601388 100644 --- a/extra/redisotel/go.mod +++ b/extra/redisotel/go.mod @@ -9,6 +9,6 @@ replace github.com/go-redis/redis/extra/rediscmd/v8 => ../rediscmd require ( github.com/go-redis/redis/extra/rediscmd/v8 v8.8.2 github.com/go-redis/redis/v8 v8.8.2 - go.opentelemetry.io/otel v0.19.0 - go.opentelemetry.io/otel/trace v0.19.0 + go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/trace v0.20.0 ) diff --git a/extra/redisotel/go.sum b/extra/redisotel/go.sum index 182608ed..1aa1088b 100644 --- a/extra/redisotel/go.sum +++ b/extra/redisotel/go.sum @@ -39,12 +39,19 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= +go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= +go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= +go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/go.mod b/go.mod index 938768f2..bfe91480 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f github.com/onsi/ginkgo v1.15.0 github.com/onsi/gomega v1.10.5 - go.opentelemetry.io/otel v0.19.0 - go.opentelemetry.io/otel/metric v0.19.0 - go.opentelemetry.io/otel/trace v0.19.0 + go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/metric v0.20.0 + go.opentelemetry.io/otel/trace v0.20.0 ) diff --git a/go.sum b/go.sum index 182608ed..b8309364 100644 --- a/go.sum +++ b/go.sum @@ -37,14 +37,14 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= -go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= -go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= -go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= -go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= -go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= -go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= -go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= +go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= +go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= +go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= +go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= +go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= +go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= +go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= From 610581533ef4c2dcd2ee14fe81937e75c767a2c5 Mon Sep 17 00:00:00 2001 From: nigel_li Date: Wed, 28 Apr 2021 13:56:44 +0800 Subject: [PATCH 2/5] Add command SMISMEMBER --- commands.go | 12 ++++++++++++ commands_test.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/commands.go b/commands.go index 37746334..9e572832 100644 --- a/commands.go +++ b/commands.go @@ -200,6 +200,7 @@ type Cmdable interface { SInter(ctx context.Context, keys ...string) *StringSliceCmd SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd + SMIsMember(ctx context.Context, key string, members ...interface{}) *BoolSliceCmd SMembers(ctx context.Context, key string) *StringSliceCmd SMembersMap(ctx context.Context, key string) *StringStructMapCmd SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd @@ -1508,6 +1509,17 @@ func (c cmdable) SIsMember(ctx context.Context, key string, member interface{}) return cmd } +// Redis `SMISMEMBER key member [member ...]` command. +func (c cmdable) SMIsMember(ctx context.Context, key string, members ...interface{}) *BoolSliceCmd { + args := make([]interface{}, 2, 2+len(members)) + args[0] = "smismember" + args[1] = key + args = appendArgs(args, members) + cmd := NewBoolSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + // Redis `SMEMBERS key` command output as a slice. func (c cmdable) SMembers(ctx context.Context, key string) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "smembers", key) diff --git a/commands_test.go b/commands_test.go index e927c58d..86c40278 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2486,6 +2486,15 @@ var _ = Describe("Commands", func() { Expect(sIsMember.Val()).To(Equal(false)) }) + It("should SMIsMember", func() { + sAdd := client.SAdd(ctx, "set", "one") + Expect(sAdd.Err()).NotTo(HaveOccurred()) + + sMIsMember := client.SMIsMember(ctx, "set", "one", "two") + Expect(sMIsMember.Err()).NotTo(HaveOccurred()) + Expect(sMIsMember.Val()).To(Equal([]bool{true, false})) + }) + It("should SMembers", func() { sAdd := client.SAdd(ctx, "set", "Hello") Expect(sAdd.Err()).NotTo(HaveOccurred()) From a57742d1710282afd7d04c6ed26127fca9cacfb0 Mon Sep 17 00:00:00 2001 From: nigel_li Date: Wed, 28 Apr 2021 14:39:03 +0800 Subject: [PATCH 3/5] Use the right redis client in tests --- commands_test.go | 2 +- redis_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commands_test.go b/commands_test.go index e927c58d..8311fcae 100644 --- a/commands_test.go +++ b/commands_test.go @@ -4677,7 +4677,7 @@ var _ = Describe("Commands", func() { client.ConfigSet(ctx, key, "0") defer client.ConfigSet(ctx, key, old[1].(string)) - err := rdb.Do(ctx, "slowlog", "reset").Err() + err := client.Do(ctx, "slowlog", "reset").Err() Expect(err).NotTo(HaveOccurred()) client.Set(ctx, "test", "true", 0) diff --git a/redis_test.go b/redis_test.go index bbfa4c14..9f189052 100644 --- a/redis_test.go +++ b/redis_test.go @@ -290,18 +290,18 @@ var _ = Describe("Client", func() { It("should set and scan time", func() { tm := time.Now() - err := rdb.Set(ctx, "now", tm, 0).Err() + err := client.Set(ctx, "now", tm, 0).Err() Expect(err).NotTo(HaveOccurred()) var tm2 time.Time - err = rdb.Get(ctx, "now").Scan(&tm2) + err = client.Get(ctx, "now").Scan(&tm2) Expect(err).NotTo(HaveOccurred()) Expect(tm2).To(BeTemporally("==", tm)) }) It("should Conn", func() { - err := rdb.Conn(ctx).Get(ctx, "this-key-does-not-exist").Err() + err := client.Conn(ctx).Get(ctx, "this-key-does-not-exist").Err() Expect(err).To(Equal(redis.Nil)) }) }) From b8cda18db915526c68aa4a59b250e60c978fe4e6 Mon Sep 17 00:00:00 2001 From: Omri Hazan Date: Wed, 28 Apr 2021 22:45:13 -0700 Subject: [PATCH 4/5] Fix typo in README (#1744) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 08a151e0..1a0e460e 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ res, err := rdb.Do(ctx, "set", "key", "value").Result() go-redis will start a redis-server and run the test cases. -The paths of redis-server bin file and redis config file are definded in `main_test.go`: +The paths of redis-server bin file and redis config file are defined in `main_test.go`: ``` var ( From 26373ef2f13351d51b481e53069063aed8dc1318 Mon Sep 17 00:00:00 2001 From: monkey Date: Thu, 13 May 2021 10:33:38 +0800 Subject: [PATCH 5/5] follow to golang-lint 1.40 Signed-off-by: monkey --- error.go | 1 + internal/hashtag/hashtag.go | 2 +- internal/log.go | 2 ++ internal/pool/pool.go | 5 ++++- internal/proto/reader.go | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/error.go b/error.go index 2ed5dc62..ad9e173e 100644 --- a/error.go +++ b/error.go @@ -10,6 +10,7 @@ import ( "github.com/go-redis/redis/v8/internal/proto" ) +// ErrClosed performs any operation on the closed client will return this error. var ErrClosed = pool.ErrClosed type Error interface { diff --git a/internal/hashtag/hashtag.go b/internal/hashtag/hashtag.go index 2fc74ad1..b3a4f211 100644 --- a/internal/hashtag/hashtag.go +++ b/internal/hashtag/hashtag.go @@ -60,7 +60,7 @@ func RandomSlot() int { return rand.Intn(slotNumber) } -// hashSlot returns a consistent slot number between 0 and 16383 +// Slot returns a consistent slot number between 0 and 16383 // for any given string key. func Slot(key string) int { if key == "" { diff --git a/internal/log.go b/internal/log.go index 3810f9e4..c8b9213d 100644 --- a/internal/log.go +++ b/internal/log.go @@ -19,6 +19,8 @@ func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) { _ = l.log.Output(2, fmt.Sprintf(format, v...)) } +// Logger calls Output to print to the stderr. +// Arguments are handled in the manner of fmt.Print. var Logger Logging = &logger{ log: log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile), } diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 74fbb37a..4d247b30 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -12,7 +12,10 @@ import ( ) var ( - ErrClosed = errors.New("redis: client is closed") + // ErrClosed performs any operation on the closed client will return this error. + ErrClosed = errors.New("redis: client is closed") + + // ErrPoolTimeout timed out waiting to get a connection from the connection pool. ErrPoolTimeout = errors.New("redis: connection pool timeout") ) diff --git a/internal/proto/reader.go b/internal/proto/reader.go index 0ab8c9d2..10d1b423 100644 --- a/internal/proto/reader.go +++ b/internal/proto/reader.go @@ -8,6 +8,7 @@ import ( "github.com/go-redis/redis/v8/internal/util" ) +// redis resp protocol data type. const ( ErrorReply = '-' StatusReply = '+'