From 9f1522a91e666ee40f807945e49396b09e4f87c2 Mon Sep 17 00:00:00 2001 From: deferdeter <166976362+deferdeter@users.noreply.github.com> Date: Wed, 17 Apr 2024 00:02:39 +0800 Subject: [PATCH 1/5] Fix typo in comment (#2972) Signed-off-by: deferdeter --- example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_test.go b/example_test.go index 62aa8cb56..28d14b65a 100644 --- a/example_test.go +++ b/example_test.go @@ -482,7 +482,7 @@ func ExampleClient_Watch() { return err } - // Actual opperation (local in optimistic lock). + // Actual operation (local in optimistic lock). n++ // Operation is committed only if the watched keys remain unchanged. From 90c7a414ac819ab9e15cc01cd0bfa6f357236585 Mon Sep 17 00:00:00 2001 From: Akash Darshan Date: Sun, 21 Apr 2024 22:52:00 +0530 Subject: [PATCH 2/5] Adding BitfieldRo in BitMapCmdable interface (#2962) Co-authored-by: Monkey --- bitmap_commands.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bitmap_commands.go b/bitmap_commands.go index 9cd808995..a21558289 100644 --- a/bitmap_commands.go +++ b/bitmap_commands.go @@ -16,6 +16,7 @@ type BitMapCmdable interface { BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd BitField(ctx context.Context, key string, values ...interface{}) *IntSliceCmd + BitFieldRO(ctx context.Context, key string, values ...interface{}) *IntSliceCmd } func (c cmdable) GetBit(ctx context.Context, key string, offset int64) *IntCmd { From fa9edecebc15475ced01a983d7f6b18db46840b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bal=C3=A1=C5=BE?= Date: Sat, 27 Apr 2024 08:42:30 +0200 Subject: [PATCH 3/5] Fix XGroup first pos key (#2983) --- stream_commands.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stream_commands.go b/stream_commands.go index 0a9869202..1ad33740c 100644 --- a/stream_commands.go +++ b/stream_commands.go @@ -178,36 +178,42 @@ func (c cmdable) XReadStreams(ctx context.Context, streams ...string) *XStreamSl func (c cmdable) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd { cmd := NewStatusCmd(ctx, "xgroup", "create", stream, group, start) + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } func (c cmdable) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd { cmd := NewStatusCmd(ctx, "xgroup", "create", stream, group, start, "mkstream") + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } func (c cmdable) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd { cmd := NewStatusCmd(ctx, "xgroup", "setid", stream, group, start) + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } func (c cmdable) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd { cmd := NewIntCmd(ctx, "xgroup", "destroy", stream, group) + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } func (c cmdable) XGroupCreateConsumer(ctx context.Context, stream, group, consumer string) *IntCmd { cmd := NewIntCmd(ctx, "xgroup", "createconsumer", stream, group, consumer) + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } func (c cmdable) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd { cmd := NewIntCmd(ctx, "xgroup", "delconsumer", stream, group, consumer) + cmd.SetFirstKeyPos(2) _ = c(ctx, cmd) return cmd } From b64d9deef330a51cfbd3e0425b6c26b27c1ee370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bal=C3=A1=C5=BE?= Date: Sun, 28 Apr 2024 06:37:44 +0200 Subject: [PATCH 4/5] Handle IPv6 in isMovedError (#2981) * Handle IPv6 in isMovedError * Simplify GetAddr --------- Co-authored-by: Monkey --- error.go | 3 +++ internal/util.go | 17 +++++++++++++++++ internal/util_test.go | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/error.go b/error.go index 8a59913be..9b348193a 100644 --- a/error.go +++ b/error.go @@ -7,6 +7,7 @@ import ( "net" "strings" + "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/proto" ) @@ -129,7 +130,9 @@ func isMovedError(err error) (moved bool, ask bool, addr string) { if ind == -1 { return false, false, "" } + addr = s[ind+1:] + addr = internal.GetAddr(addr) return } diff --git a/internal/util.go b/internal/util.go index ed81ad7aa..235a91afa 100644 --- a/internal/util.go +++ b/internal/util.go @@ -2,6 +2,7 @@ package internal import ( "context" + "net" "strings" "time" @@ -64,3 +65,19 @@ func ReplaceSpaces(s string) string { return builder.String() } + +func GetAddr(addr string) string { + ind := strings.LastIndexByte(addr, ':') + if ind == -1 { + return "" + } + + if strings.IndexByte(addr, '.') != -1 { + return addr + } + + if addr[0] == '[' { + return addr + } + return net.JoinHostPort(addr[:ind], addr[ind+1:]) +} diff --git a/internal/util_test.go b/internal/util_test.go index f090ebaa4..57f7f9fa1 100644 --- a/internal/util_test.go +++ b/internal/util_test.go @@ -51,3 +51,24 @@ func TestIsLower(t *testing.T) { Expect(isLower(str)).To(BeTrue()) }) } + +func TestGetAddr(t *testing.T) { + It("getAddr", func() { + str := "127.0.0.1:1234" + Expect(GetAddr(str)).To(Equal(str)) + + str = "[::1]:1234" + Expect(GetAddr(str)).To(Equal(str)) + + str = "[fd01:abcd::7d03]:6379" + Expect(GetAddr(str)).To(Equal(str)) + + Expect(GetAddr("::1:1234")).To(Equal("[::1]:1234")) + + Expect(GetAddr("fd01:abcd::7d03:6379")).To(Equal("[fd01:abcd::7d03]:6379")) + + Expect(GetAddr("127.0.0.1")).To(Equal("")) + + Expect(GetAddr("127")).To(Equal("")) + }) +} From 0f0a28464c3db3ff13f80c44db43dbb4ad6ac2c7 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Thu, 9 May 2024 23:52:32 -0700 Subject: [PATCH 5/5] Remove skipping span creation by checking parent spans (#2980) * Remove skipping span creation by checking parent spans * Update CHANGELOG --- CHANGELOG.md | 9 +++++++++ extra/redisotel/tracing.go | 12 ------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 297438a9f..e1652b179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## Unreleased + +### Changed + +* `go-redis` won't skip span creation if the parent spans is not recording. ([#2980](https://github.com/redis/go-redis/issues/2980)) + Users can use the OpenTelemetry sampler to control the sampling behavior. + For instance, you can use the `ParentBased(NeverSample())` sampler from `go.opentelemetry.io/otel/sdk/trace` to keep + a similar behavior (drop orphan spans) of `go-redis` as before. + ## [9.0.5](https://github.com/redis/go-redis/compare/v9.0.4...v9.0.5) (2023-05-29) diff --git a/extra/redisotel/tracing.go b/extra/redisotel/tracing.go index 2c6c1b0b5..3d5f3426c 100644 --- a/extra/redisotel/tracing.go +++ b/extra/redisotel/tracing.go @@ -91,10 +91,6 @@ func newTracingHook(connString string, opts ...TracingOption) *tracingHook { func (th *tracingHook) DialHook(hook redis.DialHook) redis.DialHook { return func(ctx context.Context, network, addr string) (net.Conn, error) { - if !trace.SpanFromContext(ctx).IsRecording() { - return hook(ctx, network, addr) - } - ctx, span := th.conf.tracer.Start(ctx, "redis.dial", th.spanOpts...) defer span.End() @@ -109,10 +105,6 @@ func (th *tracingHook) DialHook(hook redis.DialHook) redis.DialHook { func (th *tracingHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook { return func(ctx context.Context, cmd redis.Cmder) error { - if !trace.SpanFromContext(ctx).IsRecording() { - return hook(ctx, cmd) - } - fn, file, line := funcFileLine("github.com/redis/go-redis") attrs := make([]attribute.KeyValue, 0, 8) @@ -145,10 +137,6 @@ func (th *tracingHook) ProcessPipelineHook( hook redis.ProcessPipelineHook, ) redis.ProcessPipelineHook { return func(ctx context.Context, cmds []redis.Cmder) error { - if !trace.SpanFromContext(ctx).IsRecording() { - return hook(ctx, cmds) - } - fn, file, line := funcFileLine("github.com/redis/go-redis") attrs := make([]attribute.KeyValue, 0, 8)