1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-17 20:17:02 +03:00

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 <nedyalko.dyakov@gmail.com>
This commit is contained in:
milad 2025-03-06 18:23:14 +03:30 committed by GitHub
parent 162a15432b
commit 8fadbef84a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -163,6 +163,8 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
TLSConfig: o.TLSConfig, TLSConfig: o.TLSConfig,
ReplicaOnly: o.ReadOnly,
DisableIndentity: o.DisableIndentity, DisableIndentity: o.DisableIndentity,
IdentitySuffix: o.IdentitySuffix, IdentitySuffix: o.IdentitySuffix,
UnstableResp3: o.UnstableResp3, UnstableResp3: o.UnstableResp3,

View File

@ -60,6 +60,25 @@ var _ = Describe("UniversalClient", func() {
Expect(a).ToNot(Panic()) Expect(a).ToNot(Panic())
}) })
It("should connect to failover servers on slaves when readonly Options is ok", Label("NonRedisEnterprise"), func() {
client = redis.NewUniversalClient(&redis.UniversalOptions{
MasterName: sentinelName,
Addrs: sentinelAddrs,
ReadOnly: true,
})
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
roleCmd := client.Do(ctx, "ROLE")
role, err := roleCmd.Result()
Expect(err).NotTo(HaveOccurred())
roleSlice, ok := role.([]interface{})
Expect(ok).To(BeTrue())
Expect(roleSlice[0]).To(Equal("slave"))
err = client.Set(ctx, "somekey", "somevalue", 0).Err()
Expect(err).To(HaveOccurred())
})
It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() { It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonRedisEnterprise"), func() {
client = redis.NewUniversalClient(&redis.UniversalOptions{ client = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: []string{cluster.addrs()[0]}, Addrs: []string{cluster.addrs()[0]},
@ -77,3 +96,4 @@ var _ = Describe("UniversalClient", func() {
Expect(client.ClusterSlots(ctx).Val()).To(HaveLen(3)) Expect(client.ClusterSlots(ctx).Val()).To(HaveLen(3))
}) })
}) })