@@ -29,10 +29,13 @@ type Limiter interface {
29
29
30
30
// Options keeps the settings to set up redis connection.
31
31
type Options struct {
32
- // The network type, either tcp or unix.
33
- // Default is tcp.
32
+
33
+ // Network type, either tcp or unix.
34
+ //
35
+ // default: is tcp.
34
36
Network string
35
- // host:port address.
37
+
38
+ // Addr is the address formated as host:port
36
39
Addr string
37
40
38
41
// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
@@ -42,21 +45,25 @@ type Options struct {
42
45
// Network and Addr options.
43
46
Dialer func (ctx context.Context , network , addr string ) (net.Conn , error )
44
47
45
- // Hook that is called when new connection is established.
48
+ // OnConnect Hook that is called when new connection is established.
46
49
OnConnect func (ctx context.Context , cn * Conn ) error
47
50
48
51
// Protocol 2 or 3. Use the version to negotiate RESP version with redis-server.
49
- // Default is 3.
52
+ //
53
+ // default: 3.
50
54
Protocol int
51
- // Use the specified Username to authenticate the current connection
55
+
56
+ // Username is used to authenticate the current connection
52
57
// with one of the connections defined in the ACL list when connecting
53
58
// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
54
59
Username string
55
- // Optional password. Must match the password specified in the
56
- // requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
60
+
61
+ // Password is an optional password. Must match the password specified in the
62
+ // `requirepass` server configuration option (if connecting to a Redis 5.0 instance, or lower),
57
63
// or the User Password when connecting to a Redis 6.0 instance, or greater,
58
64
// that is using the Redis ACL system.
59
65
Password string
66
+
60
67
// CredentialsProvider allows the username and password to be updated
61
68
// before reconnecting. It should return the current username and password.
62
69
CredentialsProvider func () (username string , password string )
@@ -67,94 +74,128 @@ type Options struct {
67
74
// There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
68
75
CredentialsProviderContext func (ctx context.Context ) (username string , password string , err error )
69
76
70
- // Database to be selected after connecting to the server.
77
+ // DB is the database to be selected after connecting to the server.
71
78
DB int
72
79
73
- // Maximum number of retries before giving up.
74
- // Default is 3 retries; -1 (not 0) disables retries.
80
+ // MaxRetries is the maximum number of retries before giving up.
81
+ // -1 (not 0) disables retries.
82
+ //
83
+ // default: 3 retries
75
84
MaxRetries int
76
- // Minimum backoff between each retry.
77
- // Default is 8 milliseconds; -1 disables backoff.
85
+
86
+ // MinRetryBackoff is the minimum backoff between each retry.
87
+ // -1 disables backoff.
88
+ //
89
+ // default: 8 milliseconds
78
90
MinRetryBackoff time.Duration
79
- // Maximum backoff between each retry.
80
- // Default is 512 milliseconds; -1 disables backoff.
91
+
92
+ // MaxRetryBackoff is the maximum backoff between each retry.
93
+ // -1 disables backoff.
94
+ // default: 512 milliseconds;
81
95
MaxRetryBackoff time.Duration
82
96
83
- // Dial timeout for establishing new connections.
84
- // Default is 5 seconds.
97
+ // DialTimeout for establishing new connections.
98
+ //
99
+ // default: 5 seconds
85
100
DialTimeout time.Duration
86
- // Timeout for socket reads. If reached, commands will fail
101
+
102
+ // ReadTimeout for socket reads. If reached, commands will fail
87
103
// with a timeout instead of blocking. Supported values:
88
- // - `0` - default timeout (3 seconds).
89
- // - `-1` - no timeout (block indefinitely).
90
- // - `-2` - disables SetReadDeadline calls completely.
104
+ //
105
+ // - `-1` - no timeout (block indefinitely).
106
+ // - `-2` - disables SetReadDeadline calls completely.
107
+ //
108
+ // default: 3 seconds
91
109
ReadTimeout time.Duration
92
- // Timeout for socket writes. If reached, commands will fail
110
+
111
+ // WriteTimeout for socket writes. If reached, commands will fail
93
112
// with a timeout instead of blocking. Supported values:
94
- // - `0` - default timeout (3 seconds).
95
- // - `-1` - no timeout (block indefinitely).
96
- // - `-2` - disables SetWriteDeadline calls completely.
113
+ //
114
+ // - `-1` - no timeout (block indefinitely).
115
+ // - `-2` - disables SetWriteDeadline calls completely.
116
+ //
117
+ // default: 3 seconds
97
118
WriteTimeout time.Duration
119
+
98
120
// ContextTimeoutEnabled controls whether the client respects context timeouts and deadlines.
99
121
// See https://redis.uptrace.dev/guide/go-redis-debugging.html#timeouts
100
122
ContextTimeoutEnabled bool
101
123
102
- // Type of connection pool.
103
- // true for FIFO pool, false for LIFO pool.
124
+ // PoolFIFO type of connection pool.
125
+ //
126
+ // - true for FIFO pool
127
+ // - false for LIFO pool.
128
+ //
104
129
// Note that FIFO has slightly higher overhead compared to LIFO,
105
130
// but it helps closing idle connections faster reducing the pool size.
106
131
PoolFIFO bool
107
- // Base number of socket connections.
132
+
133
+ // PoolSize is the base number of socket connections.
108
134
// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
109
135
// If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize,
110
136
// you can limit it through MaxActiveConns
137
+ //
138
+ // default: 10 * runtime.GOMAXPROCS(0)
111
139
PoolSize int
112
- // Amount of time client waits for connection if all connections
140
+
141
+ // PoolTimeout is the amount of time client waits for connection if all connections
113
142
// are busy before returning an error.
114
- // Default is ReadTimeout + 1 second.
143
+ //
144
+ // default: ReadTimeout + 1 second
115
145
PoolTimeout time.Duration
116
- // Minimum number of idle connections which is useful when establishing
117
- // new connection is slow.
118
- // Default is 0. the idle connections are not closed by default.
146
+
147
+ // MinIdleConns is the minimum number of idle connections which is useful when establishing
148
+ // new connection is slow. The idle connections are not closed by default.
149
+ //
150
+ // default: 0
119
151
MinIdleConns int
120
- // Maximum number of idle connections.
121
- // Default is 0. the idle connections are not closed by default.
152
+
153
+ // MaxIdleConns is the maximum number of idle connections.
154
+ // The idle connections are not closed by default.
155
+ //
156
+ // default: 0
122
157
MaxIdleConns int
123
- // Maximum number of connections allocated by the pool at a given time.
158
+
159
+ // MaxActiveConns is the maximum number of connections allocated by the pool at a given time.
124
160
// When zero, there is no limit on the number of connections in the pool.
161
+ // If the pool is full, the next call to Get() will block until a connection is released.
125
162
MaxActiveConns int
163
+
126
164
// ConnMaxIdleTime is the maximum amount of time a connection may be idle.
127
165
// Should be less than server's timeout.
128
166
//
129
167
// Expired connections may be closed lazily before reuse.
130
168
// If d <= 0, connections are not closed due to a connection's idle time.
169
+ // -1 disables idle timeout check.
131
170
//
132
- // Default is 30 minutes. -1 disables idle timeout check.
171
+ // default: 30 minutes
133
172
ConnMaxIdleTime time.Duration
173
+
134
174
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
135
175
//
136
176
// Expired connections may be closed lazily before reuse.
137
177
// If <= 0, connections are not closed due to a connection's age.
138
178
//
139
- // Default is to not close idle connections.
179
+ // default: 0
140
180
ConnMaxLifetime time.Duration
141
181
142
- // TLS Config to use. When set, TLS will be negotiated.
182
+ // TLSConfig to use. When set, TLS will be negotiated.
143
183
TLSConfig * tls.Config
144
184
145
185
// Limiter interface used to implement circuit breaker or rate limiter.
146
186
Limiter Limiter
147
187
148
- // Enables read only queries on slave/follower nodes.
188
+ // readOnly enables read only queries on slave/follower nodes.
149
189
readOnly bool
150
190
151
- // Disable set-lib on connect. Default is false.
191
+ // DisableIndentity set-lib on connect. Default is false.
152
192
DisableIndentity bool
153
193
154
- // Add suffix to client name. Default is empty .
194
+ // IdentitySuffix - add suffix to client name.
155
195
IdentitySuffix string
156
196
157
197
// UnstableResp3 enables Unstable mode for Redis Search module with RESP3.
198
+ // When unstable mode is enabled, the client will use RESP3 protocol and only be able to use RawResult
158
199
UnstableResp3 bool
159
200
}
160
201
0 commit comments