Skip to content

Commit f2bf576

Browse files
authored
Merge branch 'master' into os-support-new-hash-commands
2 parents 2408d41 + 11efd6a commit f2bf576

File tree

12 files changed

+224
-37
lines changed

12 files changed

+224
-37
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,18 @@ By default, go-redis automatically sends the client library name and version dur
178178

179179
#### Disabling Identity Verification
180180

181-
When connection identity verification is not required or needs to be explicitly disabled, a `DisableIndentity` configuration option exists. In V10 of this library, `DisableIndentity` will become `DisableIdentity` in order to fix the associated typo.
181+
When connection identity verification is not required or needs to be explicitly disabled, a `DisableIdentity` configuration option exists.
182+
Initially there was a typo and the option was named `DisableIndentity` instead of `DisableIdentity`. The misspelled option is marked as Deprecated and will be removed in V10 of this library.
183+
Although both options will work at the moment, the correct option is `DisableIdentity`. The deprecated option will be removed in V10 of this library, so please use the correct option name to avoid any issues.
182184

183-
To disable verification, set the `DisableIndentity` option to `true` in the Redis client options:
185+
To disable verification, set the `DisableIdentity` option to `true` in the Redis client options:
184186

185187
```go
186188
rdb := redis.NewClient(&redis.Options{
187189
Addr: "localhost:6379",
188190
Password: "",
189191
DB: 0,
190-
DisableIndentity: true, // Disable set-info on connect
192+
DisableIdentity: true, // Disable set-info on connect
191193
})
192194
```
193195

bench_decode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
3030
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
3131
return stub.stubConn(initHello), nil
3232
},
33-
DisableIndentity: true,
33+
DisableIdentity: true,
3434
})
3535
return stub
3636
}
@@ -46,7 +46,7 @@ func NewClusterClientStub(resp []byte) *ClientStub {
4646
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
4747
return stub.stubConn(initHello), nil
4848
},
49-
DisableIndentity: true,
49+
DisableIdentity: true,
5050

5151
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
5252
return []ClusterSlot{

doctests/cmds_set_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// EXAMPLE: cmds_set
2+
// HIDE_START
3+
package example_commands_test
4+
5+
import (
6+
"context"
7+
"fmt"
8+
9+
"github.com/redis/go-redis/v9"
10+
)
11+
12+
// HIDE_END
13+
14+
func ExampleClient_sadd_cmd() {
15+
ctx := context.Background()
16+
17+
rdb := redis.NewClient(&redis.Options{
18+
Addr: "localhost:6379",
19+
Password: "", // no password docs
20+
DB: 0, // use default DB
21+
})
22+
23+
// REMOVE_START
24+
rdb.Del(ctx, "myset")
25+
// REMOVE_END
26+
27+
// STEP_START sadd
28+
sAddResult1, err := rdb.SAdd(ctx, "myset", "Hello").Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(sAddResult1) // >>> 1
35+
36+
sAddResult2, err := rdb.SAdd(ctx, "myset", "World").Result()
37+
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
fmt.Println(sAddResult2) // >>> 1
43+
44+
sAddResult3, err := rdb.SAdd(ctx, "myset", "World").Result()
45+
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
fmt.Println(sAddResult3) // >>> 0
51+
52+
sMembersResult, err := rdb.SMembers(ctx, "myset").Result()
53+
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
fmt.Println(sMembersResult) // >>> [Hello World]
59+
// STEP_END
60+
61+
// Output:
62+
// 1
63+
// 1
64+
// 0
65+
// [Hello World]
66+
}
67+
68+
func ExampleClient_smembers_cmd() {
69+
ctx := context.Background()
70+
71+
rdb := redis.NewClient(&redis.Options{
72+
Addr: "localhost:6379",
73+
Password: "", // no password docs
74+
DB: 0, // use default DB
75+
})
76+
77+
// REMOVE_START
78+
rdb.Del(ctx, "myset")
79+
// REMOVE_END
80+
81+
// STEP_START smembers
82+
sAddResult, err := rdb.SAdd(ctx, "myset", "Hello", "World").Result()
83+
84+
if err != nil {
85+
panic(err)
86+
}
87+
88+
fmt.Println(sAddResult) // >>> 2
89+
90+
sMembersResult, err := rdb.SMembers(ctx, "myset").Result()
91+
92+
if err != nil {
93+
panic(err)
94+
}
95+
96+
fmt.Println(sMembersResult) // >>> [Hello World]
97+
// STEP_END
98+
99+
// Output:
100+
// 2
101+
// [Hello World]
102+
}

example/otel/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/redis/go-redis/example/otel
22

33
go 1.19
4+
toolchain go1.24.1
45

56
replace github.com/redis/go-redis/v9 => ../..
67

@@ -34,9 +35,9 @@ require (
3435
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
3536
go.opentelemetry.io/otel/trace v1.22.0 // indirect
3637
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
37-
golang.org/x/net v0.33.0 // indirect
38-
golang.org/x/sys v0.28.0 // indirect
39-
golang.org/x/text v0.21.0 // indirect
38+
golang.org/x/net v0.36.0 // indirect
39+
golang.org/x/sys v0.30.0 // indirect
40+
golang.org/x/text v0.22.0 // indirect
4041
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 // indirect
4142
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
4243
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect

example/otel/go.sum

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
2+
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
23
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4+
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
35
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
46
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
57
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
68
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
79
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
10+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
811
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
912
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
1013
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -17,10 +20,13 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
1720
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
1821
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1922
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
23+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2024
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No=
2125
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU=
2226
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
27+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2328
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
29+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
2430
github.com/uptrace/uptrace-go v1.21.0 h1:oJoUjhiVT7aiuoG6B3ClVHtJozLn3cK9hQt8U5dQO1M=
2531
github.com/uptrace/uptrace-go v1.21.0/go.mod h1:/aXAFGKOqeAFBqWa1xtzLnGX2xJm1GScqz9NJ0TJjLM=
2632
go.opentelemetry.io/contrib/instrumentation/runtime v0.46.1 h1:m9ReioVPIffxjJlGNRd0d5poy+9oTro3D+YbiEzUDOc=
@@ -46,12 +52,13 @@ go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40
4652
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
4753
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
4854
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
49-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
50-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
51-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
52-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
53-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
54-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
55+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
56+
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
57+
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
58+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
59+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
60+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
61+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
5562
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5663
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 h1:/IWabOtPziuXTEtI1KYCpM6Ss7vaAkeMxk+uXV/xvZs=
5764
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1/go.mod h1:+Rvu7ElI+aLzyDQhpHMFMMltsD6m7nqpuWDd2CwJw3k=
@@ -66,3 +73,4 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
6673
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
6774
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
6875
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
76+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

options.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,18 @@ type Options struct {
148148
// Enables read only queries on slave/follower nodes.
149149
readOnly bool
150150

151-
// Disable set-lib on connect. Default is false.
151+
// DisableIndentity - Disable set-lib on connect.
152+
//
153+
// default: false
154+
//
155+
// Deprecated: Use DisableIdentity instead.
152156
DisableIndentity bool
153157

158+
// DisableIdentity is used to disable CLIENT SETINFO command on connect.
159+
//
160+
// default: false
161+
DisableIdentity bool
162+
154163
// Add suffix to client name. Default is empty.
155164
IdentitySuffix string
156165

osscluster.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,19 @@ type ClusterOptions struct {
9090
ConnMaxIdleTime time.Duration
9191
ConnMaxLifetime time.Duration
9292

93-
TLSConfig *tls.Config
94-
DisableIndentity bool // Disable set-lib on connect. Default is false.
93+
TLSConfig *tls.Config
94+
95+
// DisableIndentity - Disable set-lib on connect.
96+
//
97+
// default: false
98+
//
99+
// Deprecated: Use DisableIdentity instead.
100+
DisableIndentity bool
101+
102+
// DisableIdentity is used to disable CLIENT SETINFO command on connect.
103+
//
104+
// default: false
105+
DisableIdentity bool
95106

96107
IdentitySuffix string // Add suffix to client name. Default is empty.
97108

@@ -303,7 +314,8 @@ func (opt *ClusterOptions) clientOptions() *Options {
303314
MaxActiveConns: opt.MaxActiveConns,
304315
ConnMaxIdleTime: opt.ConnMaxIdleTime,
305316
ConnMaxLifetime: opt.ConnMaxLifetime,
306-
DisableIndentity: opt.DisableIndentity,
317+
DisableIdentity: opt.DisableIdentity,
318+
DisableIndentity: opt.DisableIdentity,
307319
IdentitySuffix: opt.IdentitySuffix,
308320
TLSConfig: opt.TLSConfig,
309321
// If ClusterSlots is populated, then we probably have an artificial

redis.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
350350
return err
351351
}
352352

353-
if !c.opt.DisableIndentity {
353+
if !c.opt.DisableIdentity && !c.opt.DisableIndentity {
354354
libName := ""
355355
libVer := Version()
356356
if c.opt.IdentitySuffix != "" {
@@ -359,7 +359,11 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
359359
p := conn.Pipeline()
360360
p.ClientSetInfo(ctx, WithLibraryName(libName))
361361
p.ClientSetInfo(ctx, WithLibraryVersion(libVer))
362-
_, _ = p.Exec(ctx)
362+
// Handle network errors (e.g. timeouts) in CLIENT SETINFO to avoid
363+
// out of order responses later on.
364+
if _, err = p.Exec(ctx); err != nil && !isRedisError(err) {
365+
return err
366+
}
363367
}
364368

365369
if c.opt.OnConnect != nil {

redis_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ var _ = Describe("Client timeout", func() {
396396
})
397397

398398
testTimeout := func() {
399+
It("SETINFO timeouts", func() {
400+
conn := client.Conn()
401+
err := conn.Ping(ctx).Err()
402+
Expect(err).To(HaveOccurred())
403+
Expect(err.(net.Error).Timeout()).To(BeTrue())
404+
})
405+
399406
It("Ping timeouts", func() {
400407
err := client.Ping(ctx).Err()
401408
Expect(err).To(HaveOccurred())

ring.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,19 @@ type RingOptions struct {
9898
TLSConfig *tls.Config
9999
Limiter Limiter
100100

101+
// DisableIndentity - Disable set-lib on connect.
102+
//
103+
// default: false
104+
//
105+
// Deprecated: Use DisableIdentity instead.
101106
DisableIndentity bool
102-
IdentitySuffix string
103-
UnstableResp3 bool
107+
108+
// DisableIdentity is used to disable CLIENT SETINFO command on connect.
109+
//
110+
// default: false
111+
DisableIdentity bool
112+
IdentitySuffix string
113+
UnstableResp3 bool
104114
}
105115

106116
func (opt *RingOptions) init() {
@@ -167,9 +177,11 @@ func (opt *RingOptions) clientOptions() *Options {
167177
TLSConfig: opt.TLSConfig,
168178
Limiter: opt.Limiter,
169179

180+
DisableIdentity: opt.DisableIdentity,
170181
DisableIndentity: opt.DisableIndentity,
171-
IdentitySuffix: opt.IdentitySuffix,
172-
UnstableResp3: opt.UnstableResp3,
182+
183+
IdentitySuffix: opt.IdentitySuffix,
184+
UnstableResp3: opt.UnstableResp3,
173185
}
174186
}
175187

0 commit comments

Comments
 (0)