63
63
64
64
// ClientOption should be passed to NewClient to construct a Client
65
65
type ClientOption struct {
66
- // TCP & TLS
67
- // Dialer can be used to customized how rueidis connect to a redis instance via TCP, including:
68
- // - Timeout, the default is DefaultDialTimeout
69
- // - KeepAlive, the default is DefaultTCPKeepAlive
70
- // The Dialer.KeepAlive interval is used to detect an unresponsive idle tcp connection.
71
- // OS takes at least (tcp_keepalive_probes+1)*Dialer.KeepAlive time to conclude an idle connection to be unresponsive.
72
- // For example: DefaultTCPKeepAlive = 1s and the default of tcp_keepalive_probes on Linux is 9.
73
- // Therefore, it takes at least 10s to kill an idle and unresponsive tcp connection on Linux by default.
74
- Dialer net.Dialer
75
66
TLSConfig * tls.Config
76
67
77
68
// DialFn allows for a custom function to be used to create net.Conn connections
@@ -89,18 +80,45 @@ type ClientOption struct {
89
80
// NOTE: This function can't be used with ReplicaOnly option.
90
81
SendToReplicas func (cmd Completed ) bool
91
82
83
+ // AuthCredentialsFn allows for setting the AUTH username and password dynamically on each connection attempt to
84
+ // support rotating credentials
85
+ AuthCredentialsFn func (AuthCredentialsContext ) (AuthCredentials , error )
86
+
87
+ // RetryDelay is the function that returns the delay that should be used before retrying the attempt.
88
+ // The default is an exponential backoff with a maximum delay of 1 second.
89
+ // Only used when DisableRetry is false.
90
+ RetryDelay RetryDelayFn
91
+
92
+ // ReplicaSelector selects a replica node when `SendToReplicas` returns true.
93
+ // If the function is set, the client will send selected command to the replica node.
94
+ // Returned value is the index of the replica node in the replicas slice.
95
+ // If the returned value is out of range, the primary node will be selected.
96
+ // If primary node does not have any replica, the primary node will be selected
97
+ // and function will not be called.
98
+ // Currently only used for cluster client.
99
+ // Each ReplicaInfo must not be modified.
100
+ // NOTE: This function can't be used with ReplicaOnly option.
101
+ // NOTE: This function must be used with SendToReplicas function.
102
+ ReplicaSelector func (slot uint16 , replicas []ReplicaInfo ) int
103
+
92
104
// Sentinel options, including MasterSet and Auth options
93
105
Sentinel SentinelOption
94
106
107
+ // TCP & TLS
108
+ // Dialer can be used to customized how rueidis connect to a redis instance via TCP, including:
109
+ // - Timeout, the default is DefaultDialTimeout
110
+ // - KeepAlive, the default is DefaultTCPKeepAlive
111
+ // The Dialer.KeepAlive interval is used to detect an unresponsive idle tcp connection.
112
+ // OS takes at least (tcp_keepalive_probes+1)*Dialer.KeepAlive time to conclude an idle connection to be unresponsive.
113
+ // For example: DefaultTCPKeepAlive = 1s and the default of tcp_keepalive_probes on Linux is 9.
114
+ // Therefore, it takes at least 10s to kill an idle and unresponsive tcp connection on Linux by default.
115
+ Dialer net.Dialer
116
+
95
117
// Redis AUTH parameters
96
118
Username string
97
119
Password string
98
120
ClientName string
99
121
100
- // AuthCredentialsFn allows for setting the AUTH username and password dynamically on each connection attempt to
101
- // support rotating credentials
102
- AuthCredentialsFn func (AuthCredentialsContext ) (AuthCredentials , error )
103
-
104
122
// ClientSetInfo will assign various info attributes to the current connection.
105
123
// Note that ClientSetInfo should have exactly 2 values, the lib name and the lib version respectively.
106
124
ClientSetInfo []string
@@ -170,6 +188,9 @@ type ClientOption struct {
170
188
// produce notable CPU usage reduction under load. Ref: https://github.com/redis/rueidis/issues/156
171
189
MaxFlushDelay time.Duration
172
190
191
+ // ClusterOption is the options for the redis cluster client.
192
+ ClusterOption ClusterOption
193
+
173
194
// DisableTCPNoDelay turns on Nagle's algorithm in pipelining mode by using conn.SetNoDelay(false).
174
195
// Turning this on can result in lower p99 latencies and lower CPU usages if all your requests are small.
175
196
// But if you have large requests or fast network, this might degrade the performance. Ref: https://github.com/redis/rueidis/pull/650
@@ -181,10 +202,6 @@ type ClientOption struct {
181
202
ClientNoTouch bool
182
203
// DisableRetry disables retrying read-only commands under network errors
183
204
DisableRetry bool
184
- // RetryDelay is the function that returns the delay that should be used before retrying the attempt.
185
- // The default is an exponential backoff with a maximum delay of 1 second.
186
- // Only used when DisableRetry is false.
187
- RetryDelay RetryDelayFn
188
205
// DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti
189
206
DisableCache bool
190
207
// DisableAutoPipelining makes rueidis.Client always pick a connection from the BlockingPool to serve each request.
@@ -206,21 +223,6 @@ type ClientOption struct {
206
223
// even if we're above the configured client eviction threshold.
207
224
ClientNoEvict bool
208
225
209
- // ClusterOption is the options for the redis cluster client.
210
- ClusterOption ClusterOption
211
-
212
- // ReplicaSelector selects a replica node when `SendToReplicas` returns true.
213
- // If the function is set, the client will send selected command to the replica node.
214
- // Returned value is the index of the replica node in the replicas slice.
215
- // If the returned value is out of range, the primary node will be selected.
216
- // If primary node does not have any replica, the primary node will be selected
217
- // and function will not be called.
218
- // Currently only used for cluster client.
219
- // Each ReplicaInfo must not be modified.
220
- // NOTE: This function can't be used with ReplicaOnly option.
221
- // NOTE: This function must be used with SendToReplicas function.
222
- ReplicaSelector func (slot uint16 , replicas []ReplicaInfo ) int
223
-
224
226
// EnableReplicaAZInfo enables the client to load the replica node's availability zone.
225
227
// If true, the client will set the `AZ` field in `ReplicaInfo`.
226
228
EnableReplicaAZInfo bool
0 commit comments