Skip to content

Commit 8fadbef

Browse files
smiladndyakov
andauthored
add readOnly on failover opts (#3281)
* add readOnly on failover opts add failover that if is True it connects to slaves * add test * add test for slave connect * fix test * fix tests * skip Flaky * add more tests on slave * add test * delete file * Update universal_test.go enable previously skipped test. * rm skip from sentinels * rm tmp files * Update universal_test.go don't run sentinel test in RE * Update universal_test.go --------- Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent 162a154 commit 8fadbef

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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)