-
Notifications
You must be signed in to change notification settings - Fork 202
feat: Add Mode()
Method to rueidis.Client
for Detecting Client Mode
#794
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
Conversation
Signed-off-by: Cheyu Wu <[email protected]>
Signed-off-by: Cheyu Wu <[email protected]>
rueidis.go
Outdated
// https://github.com/valkey-io/valkey/blob/1a34a4ff7f101bb6b17a0b5e9aa3bf7d6bd29f68/src/networking.c#L4118-L4124 | ||
ModeCluster ClientMode = "cluster" | ||
ModeSentinel ClientMode = "sentinel" | ||
ModeStandalone ClientMode = "standalone" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be with Client
prefix:
ClientModeCluster ClientMode = "cluster"
ClientModeSentinel ClientMode = "sentinel"
ClientModeStandalone ClientMode = "standalone"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I will fix this
also cc @rueian |
client.go
Outdated
@@ -189,6 +190,10 @@ func (c *singleClient) Nodes() map[string]Client { | |||
return map[string]Client{c.conn.Addr(): c} | |||
} | |||
|
|||
func (c *singleClient) Mode() ClientMode { | |||
return c.mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return c.mode | |
return ClientModeStandalone |
client.go
Outdated
@@ -16,6 +16,7 @@ type singleClient struct { | |||
cmd Builder | |||
retry bool | |||
DisableCache bool | |||
mode ClientMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode ClientMode |
cluster.go
Outdated
@@ -57,6 +58,7 @@ func newClusterClient(opt *ClientOption, connFn connFn, retryer retryHandler) (* | |||
retry: !opt.DisableRetry, | |||
retryHandler: retryer, | |||
stopCh: make(chan struct{}), | |||
mode: ClientModeCluster, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode: ClientModeCluster, |
cluster.go
Outdated
@@ -1203,6 +1205,10 @@ func (c *clusterClient) Nodes() map[string]Client { | |||
return _nodes | |||
} | |||
|
|||
func (c *clusterClient) Mode() ClientMode { | |||
return c.mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return c.mode | |
return ClientModeCluster |
sentinel.go
Outdated
@@ -26,6 +26,7 @@ func newSentinelClient(opt *ClientOption, connFn connFn, retryer retryHandler) ( | |||
retry: !opt.DisableRetry, | |||
retryHandler: retryer, | |||
replica: opt.ReplicaOnly, | |||
mode: ClientModeSentinel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode: ClientModeSentinel, |
sentinel.go
Outdated
@@ -56,6 +57,7 @@ type sentinelClient struct { | |||
cmd Builder | |||
retry bool | |||
replica bool | |||
mode ClientMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode ClientMode |
sentinel.go
Outdated
@@ -218,6 +220,10 @@ func (c *sentinelClient) Nodes() map[string]Client { | |||
return map[string]Client{conn.Addr(): newSingleClientWithConn(conn, c.cmd, c.retry, disableCache, c.retryHandler)} | |||
} | |||
|
|||
func (c *sentinelClient) Mode() ClientMode { | |||
return c.mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return c.mode | |
return ClientModeSentinel |
Signed-off-by: Cheyu Wu <[email protected]>
1ad61f9
to
6d9ed43
Compare
Hi @rueian, I have solved those issues, PTAL |
Signed-off-by: Cheyu Wu <[email protected]>
Merged. Thanks @CheyuWu! |
Why do we need this?
Previously, Centrifugo required explicit Redis Cluster configuration because the Centrifuge library generates keys differently in cluster mode (using hash tags). However, this approach is inconvenient because cloud providers typically provide a Redis URL (e.g.,
redis://...
) without explicitly indicating whether it is a standalone Redis or a Redis Cluster. This prevents users from simply reusing the endpoint when starting Centrifugo.New Interface Definition
Closes #790