Skip to content

Commit 2a97f2e

Browse files
committed
fix build
1 parent 5fac913 commit 2a97f2e

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

example_instrumentation_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func Example_instrumentation() {
5151
rdb.AddHook(redisHook{})
5252

5353
rdb.Ping(ctx)
54-
// Output: starting processing: <[ping]>
54+
// Output:
55+
// starting processing: <[ping]>
5556
// dialing tcp :6379
5657
// finished dialing tcp :6379
5758
// starting processing: <[hello 3]>
@@ -61,7 +62,8 @@ func Example_instrumentation() {
6162

6263
func ExamplePipeline_instrumentation() {
6364
rdb := redis.NewClient(&redis.Options{
64-
Addr: ":6379",
65+
Addr: ":6379",
66+
DisableIdentity: true,
6567
})
6668
rdb.AddHook(redisHook{})
6769

@@ -70,16 +72,19 @@ func ExamplePipeline_instrumentation() {
7072
pipe.Ping(ctx)
7173
return nil
7274
})
73-
// Output: pipeline starting processing: [ping: ping: ]
74-
// Output: pipeline starting processing: [[ping] [ping]]
75+
// Output:
76+
// pipeline starting processing: [[ping] [ping]]
7577
// dialing tcp :6379
7678
// finished dialing tcp :6379
79+
// starting processing: <[hello 3]>
80+
// finished processing: <[hello 3]>
7781
// pipeline finished processing: [[ping] [ping]]
7882
}
7983

8084
func ExampleClient_Watch_instrumentation() {
8185
rdb := redis.NewClient(&redis.Options{
82-
Addr: ":6379",
86+
Addr: ":6379",
87+
DisableIdentity: true,
8388
})
8489
rdb.AddHook(redisHook{})
8590

@@ -92,6 +97,8 @@ func ExampleClient_Watch_instrumentation() {
9297
// starting processing: <[watch foo]>
9398
// dialing tcp :6379
9499
// finished dialing tcp :6379
100+
// starting processing: <[hello 3]>
101+
// finished processing: <[hello 3]>
95102
// finished processing: <[watch foo]>
96103
// starting processing: <[ping]>
97104
// finished processing: <[ping]>

redis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
394394
// or it could be DragonflyDB or a third-party redis-proxy. They all respond
395395
// with different error string results for unsupported commands, making it
396396
// difficult to rely on error strings to determine all results.
397-
return fmt.Errorf("failed to initialize connection: %w", err)
397+
return err
398398
} else if password != "" {
399399
// Try legacy AUTH command if HELLO failed
400400
err = c.reAuthConnection(ctx, conn)(auth.NewBasicCredentials(username, password))
@@ -434,7 +434,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
434434
// Handle network errors (e.g. timeouts) in CLIENT SETINFO to avoid
435435
// out of order responses later on.
436436
if _, err = p.Exec(ctx); err != nil && !isRedisError(err) {
437-
return fmt.Errorf("failed to set client identity: %w", err)
437+
return err
438438
}
439439
}
440440

ring_test.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,17 @@ var _ = Describe("Redis Ring", func() {
357357
ring.AddHook(&hook{
358358
processPipelineHook: func(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
359359
return func(ctx context.Context, cmds []redis.Cmder) error {
360-
Expect(cmds).To(HaveLen(1))
360+
// skip the connection initialization
361+
if cmds[0].Name() == "hello" || cmds[0].Name() == "client" {
362+
return nil
363+
}
364+
Expect(len(cmds)).To(BeNumerically(">", 0))
361365
Expect(cmds[0].String()).To(Equal("ping: "))
362366
stack = append(stack, "ring.BeforeProcessPipeline")
363367

364368
err := hook(ctx, cmds)
365369

366-
Expect(cmds).To(HaveLen(1))
370+
Expect(len(cmds)).To(BeNumerically(">", 0))
367371
Expect(cmds[0].String()).To(Equal("ping: PONG"))
368372
stack = append(stack, "ring.AfterProcessPipeline")
369373

@@ -376,13 +380,17 @@ var _ = Describe("Redis Ring", func() {
376380
shard.AddHook(&hook{
377381
processPipelineHook: func(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
378382
return func(ctx context.Context, cmds []redis.Cmder) error {
379-
Expect(cmds).To(HaveLen(1))
383+
// skip the connection initialization
384+
if cmds[0].Name() == "hello" || cmds[0].Name() == "client" {
385+
return nil
386+
}
387+
Expect(len(cmds)).To(BeNumerically(">", 0))
380388
Expect(cmds[0].String()).To(Equal("ping: "))
381389
stack = append(stack, "shard.BeforeProcessPipeline")
382390

383391
err := hook(ctx, cmds)
384392

385-
Expect(cmds).To(HaveLen(1))
393+
Expect(len(cmds)).To(BeNumerically(">", 0))
386394
Expect(cmds[0].String()).To(Equal("ping: PONG"))
387395
stack = append(stack, "shard.AfterProcessPipeline")
388396

@@ -416,14 +424,18 @@ var _ = Describe("Redis Ring", func() {
416424
processPipelineHook: func(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
417425
return func(ctx context.Context, cmds []redis.Cmder) error {
418426
defer GinkgoRecover()
427+
// skip the connection initialization
428+
if cmds[0].Name() == "hello" || cmds[0].Name() == "client" {
429+
return nil
430+
}
419431

420-
Expect(cmds).To(HaveLen(3))
432+
Expect(len(cmds)).To(BeNumerically(">=", 3))
421433
Expect(cmds[1].String()).To(Equal("ping: "))
422434
stack = append(stack, "ring.BeforeProcessPipeline")
423435

424436
err := hook(ctx, cmds)
425437

426-
Expect(cmds).To(HaveLen(3))
438+
Expect(len(cmds)).To(BeNumerically(">=", 3))
427439
Expect(cmds[1].String()).To(Equal("ping: PONG"))
428440
stack = append(stack, "ring.AfterProcessPipeline")
429441

@@ -437,14 +449,18 @@ var _ = Describe("Redis Ring", func() {
437449
processPipelineHook: func(hook redis.ProcessPipelineHook) redis.ProcessPipelineHook {
438450
return func(ctx context.Context, cmds []redis.Cmder) error {
439451
defer GinkgoRecover()
452+
// skip the connection initialization
453+
if cmds[0].Name() == "hello" || cmds[0].Name() == "client" {
454+
return nil
455+
}
440456

441-
Expect(cmds).To(HaveLen(3))
457+
Expect(len(cmds)).To(BeNumerically(">=", 3))
442458
Expect(cmds[1].String()).To(Equal("ping: "))
443459
stack = append(stack, "shard.BeforeProcessPipeline")
444460

445461
err := hook(ctx, cmds)
446462

447-
Expect(cmds).To(HaveLen(3))
463+
Expect(len(cmds)).To(BeNumerically(">=", 3))
448464
Expect(cmds[1].String()).To(Equal("ping: PONG"))
449465
stack = append(stack, "shard.AfterProcessPipeline")
450466

0 commit comments

Comments
 (0)