Skip to content

Commit c201e02

Browse files
authored
Merge branch 'master' into do_cmd_for_simple_conn
2 parents 6e5adac + 8fadbef commit c201e02

File tree

6 files changed

+89
-5
lines changed

6 files changed

+89
-5
lines changed

doctests/query_range_test.go

Lines changed: 22 additions & 4 deletions
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

Lines changed: 9 additions & 0 deletions
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:

osscluster.go

Lines changed: 3 additions & 1 deletion
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

Lines changed: 33 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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)