Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly options on failover #3277

Open
smilad opened this issue Feb 17, 2025 · 3 comments
Open

ReadOnly options on failover #3277

smilad opened this issue Feb 17, 2025 · 3 comments
Assignees
Labels

Comments

@smilad
Copy link

smilad commented Feb 17, 2025

hi
You must map the readOnly Option to Replicaonly options
if we want to connect to the slaves in sentinel is not suported

func (o *UniversalOptions) Failover() *FailoverOptions {
if len(o.Addrs) == 0 {
o.Addrs = []string{"127.0.0.1:26379"}
}

return &FailoverOptions{
	SentinelAddrs: o.Addrs,
	MasterName:    o.MasterName,
	ClientName:    o.ClientName,

	Dialer:    o.Dialer,
	OnConnect: o.OnConnect,

	DB:               o.DB,
	Protocol:         o.Protocol,
	Username:         o.Username,
	Password:         o.Password,
	SentinelUsername: o.SentinelUsername,
	SentinelPassword: o.SentinelPassword,

	MaxRetries:      o.MaxRetries,
	MinRetryBackoff: o.MinRetryBackoff,
	MaxRetryBackoff: o.MaxRetryBackoff,

	DialTimeout:           o.DialTimeout,
	ReadTimeout:           o.ReadTimeout,
	WriteTimeout:          o.WriteTimeout,
	ContextTimeoutEnabled: o.ContextTimeoutEnabled,

	PoolFIFO:        o.PoolFIFO,
	PoolSize:        o.PoolSize,
	PoolTimeout:     o.PoolTimeout,
	MinIdleConns:    o.MinIdleConns,
	MaxIdleConns:    o.MaxIdleConns,
	MaxActiveConns:  o.MaxActiveConns,
	ConnMaxIdleTime: o.ConnMaxIdleTime,
	ConnMaxLifetime: o.ConnMaxLifetime,

	TLSConfig: o.TLSConfig,

	DisableIndentity: o.DisableIndentity,
	IdentitySuffix:   o.IdentitySuffix,
	UnstableResp3:    o.UnstableResp3,
}

}

@farazff
Copy link

farazff commented Feb 17, 2025

Hi,
I have the same problem. When using universalOpts with sentinel, the new function uses failoverOpts which ignore the ReadOnly field in creating the Failover.

We need this change:

// Failover returns failover options created from the universal options.
func (o *UniversalOptions) Failover() *FailoverOptions {
if len(o.Addrs) == 0 {
o.Addrs = []string{"127.0.0.1:26379"}
}

return &FailoverOptions{
	SentinelAddrs: o.Addrs,
	MasterName:    o.MasterName,
	ClientName:    o.ClientName,

	Dialer:    o.Dialer,
	OnConnect: o.OnConnect,

	DB:               o.DB,
	Protocol:         o.Protocol,
	Username:         o.Username,
	Password:         o.Password,
	SentinelUsername: o.SentinelUsername,
	SentinelPassword: o.SentinelPassword,

	MaxRetries:      o.MaxRetries,
	MinRetryBackoff: o.MinRetryBackoff,
	MaxRetryBackoff: o.MaxRetryBackoff,

	DialTimeout:           o.DialTimeout,
	ReadTimeout:           o.ReadTimeout,
	WriteTimeout:          o.WriteTimeout,
	ContextTimeoutEnabled: o.ContextTimeoutEnabled,

	PoolFIFO:        o.PoolFIFO,
	PoolSize:        o.PoolSize,
	PoolTimeout:     o.PoolTimeout,
	MinIdleConns:    o.MinIdleConns,
	MaxIdleConns:    o.MaxIdleConns,
	ConnMaxIdleTime: o.ConnMaxIdleTime,
	ConnMaxLifetime: o.ConnMaxLifetime,
	**_ReplicaOnly:     o.ReadOnly,_**

	TLSConfig: o.TLSConfig,
}

}

@smilad
Copy link
Author

smilad commented Feb 18, 2025

it fixed it this pull request
please accept and publish it:

#3281

@ndyakov
Copy link
Collaborator

ndyakov commented Feb 19, 2025

Hey @smilad , @farazff . I briefly took a look at the PR, left a comment there. Let's add couple of test cases for the change and we can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants