Skip to content

Commit 944c4b9

Browse files
authored
Merge branch 'master' into enabling-dialect-2-on-default
2 parents 32eb6f1 + 310ce55 commit 944c4b9

9 files changed

+122
-12
lines changed

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66
[![codecov](https://codecov.io/github/redis/go-redis/graph/badge.svg?token=tsrCZKuSSw)](https://codecov.io/github/redis/go-redis)
77
[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)
88

9-
> go-redis is brought to you by :star: [**uptrace/uptrace**](https://github.com/uptrace/uptrace).
10-
> Uptrace is an open-source APM tool that supports distributed tracing, metrics, and logs. You can
11-
> use it to monitor applications and set up automatic alerts to receive notifications via email,
12-
> Slack, Telegram, and others.
13-
>
14-
> See [OpenTelemetry](https://github.com/redis/go-redis/tree/master/example/otel) example which
15-
> demonstrates how you can use Uptrace to monitor go-redis.
9+
> go-redis is the official Redis client library for the Go programming language. It offers a straightforward interface for interacting with Redis servers.
1610
1711
## Supported versions
1812

@@ -297,6 +291,14 @@ REDIS_PORT=9999 go test <your options>
297291

298292
## Contributors
299293

294+
> The go-redis project was originally initiated by :star: [**uptrace/uptrace**](https://github.com/uptrace/uptrace).
295+
> Uptrace is an open-source APM tool that supports distributed tracing, metrics, and logs. You can
296+
> use it to monitor applications and set up automatic alerts to receive notifications via email,
297+
> Slack, Telegram, and others.
298+
>
299+
> See [OpenTelemetry](https://github.com/redis/go-redis/tree/master/example/otel) example which
300+
> demonstrates how you can use Uptrace to monitor go-redis.
301+
300302
Thanks to all the people who already contributed!
301303

302304
<a href="https://github.com/redis/go-redis/graphs/contributors">

commands_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -2626,6 +2626,23 @@ var _ = Describe("Commands", func() {
26262626
))
26272627
})
26282628

2629+
It("should HStrLen", func() {
2630+
hSet := client.HSet(ctx, "hash", "key", "hello")
2631+
Expect(hSet.Err()).NotTo(HaveOccurred())
2632+
2633+
hStrLen := client.HStrLen(ctx, "hash", "key")
2634+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2635+
Expect(hStrLen.Val()).To(Equal(int64(len("hello"))))
2636+
2637+
nonHStrLen := client.HStrLen(ctx, "hash", "keyNon")
2638+
Expect(hStrLen.Err()).NotTo(HaveOccurred())
2639+
Expect(nonHStrLen.Val()).To(Equal(int64(0)))
2640+
2641+
hDel := client.HDel(ctx, "hash", "key")
2642+
Expect(hDel.Err()).NotTo(HaveOccurred())
2643+
Expect(hDel.Val()).To(Equal(int64(1)))
2644+
})
2645+
26292646
It("should HExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
26302647
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images")
26312648
res, err := client.HExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()
@@ -2642,6 +2659,7 @@ var _ = Describe("Commands", func() {
26422659
Expect(res).To(Equal([]int64{1, 1, -2}))
26432660
})
26442661

2662+
26452663
It("should HPExpire", Label("hash-expiration", "NonRedisEnterprise"), func() {
26462664
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images")
26472665
res, err := client.HPExpire(ctx, "no_such_key", 10*time.Second, "field1", "field2", "field3").Result()

doctests/query_range_test.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ func ExampleClient_query_range() {
230230
FieldName: "price",
231231
},
232232
},
233+
SortBy: []redis.FTSearchSortBy{
234+
{
235+
FieldName: "price",
236+
Asc: true,
237+
},
238+
},
233239
},
234240
).Result()
235241

@@ -263,6 +269,12 @@ func ExampleClient_query_range() {
263269
FieldName: "price",
264270
},
265271
},
272+
SortBy: []redis.FTSearchSortBy{
273+
{
274+
FieldName: "price",
275+
Asc: true,
276+
},
277+
},
266278
},
267279
).Result()
268280

@@ -289,6 +301,12 @@ func ExampleClient_query_range() {
289301
FieldName: "price",
290302
},
291303
},
304+
SortBy: []redis.FTSearchSortBy{
305+
{
306+
FieldName: "price",
307+
Asc: true,
308+
},
309+
},
292310
Filters: []redis.FTSearchFilter{
293311
{
294312
FieldName: "price",
@@ -354,19 +372,19 @@ func ExampleClient_query_range() {
354372

355373
// Output:
356374
// 3
357-
// bicycle:2 : price 815
358375
// bicycle:5 : price 810
376+
// bicycle:2 : price 815
359377
// bicycle:9 : price 815
360378
// 3
361-
// bicycle:2 : price 815
362379
// bicycle:5 : price 810
380+
// bicycle:2 : price 815
363381
// bicycle:9 : price 815
364382
// 5
365383
// bicycle:1 : price 1200
366-
// bicycle:4 : price 3200
384+
// bicycle:8 : price 1200
367385
// bicycle:6 : price 2300
386+
// bicycle:4 : price 3200
368387
// bicycle:3 : price 3400
369-
// bicycle:8 : price 1200
370388
// 7
371389
// bicycle:0 : price 270
372390
// bicycle:7 : price 430

error.go

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ type Error interface {
3838

3939
var _ Error = proto.RedisError("")
4040

41+
func isContextError(err error) bool {
42+
switch err {
43+
case context.Canceled, context.DeadlineExceeded:
44+
return true
45+
default:
46+
return false
47+
}
48+
}
49+
4150
func shouldRetry(err error, retryTimeout bool) bool {
4251
switch err {
4352
case io.EOF, io.ErrUnexpectedEOF:

hash_commands.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type HashCmdable interface {
2323
HVals(ctx context.Context, key string) *StringSliceCmd
2424
HRandField(ctx context.Context, key string, count int) *StringSliceCmd
2525
HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd
26+
HStrLen(ctx context.Context, key, field string) *IntCmd
2627
HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
2728
HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd
2829
HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd
@@ -190,6 +191,11 @@ func (c cmdable) HScan(ctx context.Context, key string, cursor uint64, match str
190191
return cmd
191192
}
192193

194+
func (c cmdable) HStrLen(ctx context.Context, key, field string) *IntCmd {
195+
cmd := NewIntCmd(ctx, "hstrlen", key, field)
196+
_ = c(ctx, cmd)
197+
return cmd
198+
}
193199
func (c cmdable) HScanNoValues(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd {
194200
args := []interface{}{"hscan", key, cursor}
195201
if match != "" {

osscluster.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,9 @@ func (c *ClusterClient) processPipelineNode(
13501350
_ = node.Client.withProcessPipelineHook(ctx, cmds, func(ctx context.Context, cmds []Cmder) error {
13511351
cn, err := node.Client.getConn(ctx)
13521352
if err != nil {
1353-
node.MarkAsFailing()
1353+
if !isContextError(err) {
1354+
node.MarkAsFailing()
1355+
}
13541356
_ = c.mapCmdsByNode(ctx, failedCmds, cmds)
13551357
setCmdsErr(cmds, err)
13561358
return err

osscluster_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,39 @@ var _ = Describe("ClusterClient", func() {
539539
AfterEach(func() {})
540540

541541
assertPipeline()
542+
543+
It("doesn't fail node with context.Canceled error", func() {
544+
ctx, cancel := context.WithCancel(context.Background())
545+
cancel()
546+
pipe.Set(ctx, "A", "A_value", 0)
547+
_, err := pipe.Exec(ctx)
548+
549+
Expect(err).To(HaveOccurred())
550+
Expect(errors.Is(err, context.Canceled)).To(BeTrue())
551+
552+
clientNodes, _ := client.Nodes(ctx, "A")
553+
554+
for _, node := range clientNodes {
555+
Expect(node.Failing()).To(BeFalse())
556+
}
557+
})
558+
559+
It("doesn't fail node with context.DeadlineExceeded error", func() {
560+
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
561+
defer cancel()
562+
563+
pipe.Set(ctx, "A", "A_value", 0)
564+
_, err := pipe.Exec(ctx)
565+
566+
Expect(err).To(HaveOccurred())
567+
Expect(errors.Is(err, context.DeadlineExceeded)).To(BeTrue())
568+
569+
clientNodes, _ := client.Nodes(ctx, "A")
570+
571+
for _, node := range clientNodes {
572+
Expect(node.Failing()).To(BeFalse())
573+
}
574+
})
542575
})
543576

544577
Describe("with TxPipeline", func() {

universal.go

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
163163

164164
TLSConfig: o.TLSConfig,
165165

166+
ReplicaOnly: o.ReadOnly,
167+
166168
DisableIndentity: o.DisableIndentity,
167169
IdentitySuffix: o.IdentitySuffix,
168170
UnstableResp3: o.UnstableResp3,

universal_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ var _ = Describe("UniversalClient", func() {
6060
Expect(a).ToNot(Panic())
6161
})
6262

63+
It("should connect to failover servers on slaves when readonly Options is ok", Label("NonRedisEnterprise"), func() {
64+
client = redis.NewUniversalClient(&redis.UniversalOptions{
65+
MasterName: sentinelName,
66+
Addrs: sentinelAddrs,
67+
ReadOnly: true,
68+
})
69+
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
70+
71+
roleCmd := client.Do(ctx, "ROLE")
72+
role, err := roleCmd.Result()
73+
Expect(err).NotTo(HaveOccurred())
74+
75+
roleSlice, ok := role.([]interface{})
76+
Expect(ok).To(BeTrue())
77+
Expect(roleSlice[0]).To(Equal("slave"))
78+
79+
err = client.Set(ctx, "somekey", "somevalue", 0).Err()
80+
Expect(err).To(HaveOccurred())
81+
})
6382
It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() {
6483
client = redis.NewUniversalClient(&redis.UniversalOptions{
6584
Addrs: []string{cluster.addrs()[0]},
@@ -77,3 +96,4 @@ var _ = Describe("UniversalClient", func() {
7796
Expect(client.ClusterSlots(ctx).Val()).To(HaveLen(3))
7897
})
7998
})
99+

0 commit comments

Comments
 (0)