@@ -29,10 +29,13 @@ type Limiter interface {
2929
3030// Options keeps the settings to set up redis connection.
3131type 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.
3436 Network string
35- // host:port address.
37+
38+ // Addr is the address formated as host:port
3639 Addr string
3740
3841 // ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
@@ -42,21 +45,25 @@ type Options struct {
4245 // Network and Addr options.
4346 Dialer func (ctx context.Context , network , addr string ) (net.Conn , error )
4447
45- // Hook that is called when new connection is established.
48+ // OnConnect Hook that is called when new connection is established.
4649 OnConnect func (ctx context.Context , cn * Conn ) error
4750
4851 // Protocol 2 or 3. Use the version to negotiate RESP version with redis-server.
49- // Default is 3.
52+ //
53+ // default: 3.
5054 Protocol int
51- // Use the specified Username to authenticate the current connection
55+
56+ // Username is used to authenticate the current connection
5257 // with one of the connections defined in the ACL list when connecting
5358 // to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
5459 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),
5763 // or the User Password when connecting to a Redis 6.0 instance, or greater,
5864 // that is using the Redis ACL system.
5965 Password string
66+
6067 // CredentialsProvider allows the username and password to be updated
6168 // before reconnecting. It should return the current username and password.
6269 CredentialsProvider func () (username string , password string )
@@ -67,94 +74,128 @@ type Options struct {
6774 // There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
6875 CredentialsProviderContext func (ctx context.Context ) (username string , password string , err error )
6976
70- // Database to be selected after connecting to the server.
77+ // DB is the database to be selected after connecting to the server.
7178 DB int
7279
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
7584 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
7890 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;
8195 MaxRetryBackoff time.Duration
8296
83- // Dial timeout for establishing new connections.
84- // Default is 5 seconds.
97+ // DialTimeout for establishing new connections.
98+ //
99+ // default: 5 seconds
85100 DialTimeout time.Duration
86- // Timeout for socket reads. If reached, commands will fail
101+
102+ // ReadTimeout for socket reads. If reached, commands will fail
87103 // 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
91109 ReadTimeout time.Duration
92- // Timeout for socket writes. If reached, commands will fail
110+
111+ // WriteTimeout for socket writes. If reached, commands will fail
93112 // 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
97118 WriteTimeout time.Duration
119+
98120 // ContextTimeoutEnabled controls whether the client respects context timeouts and deadlines.
99121 // See https://redis.uptrace.dev/guide/go-redis-debugging.html#timeouts
100122 ContextTimeoutEnabled bool
101123
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+ //
104129 // Note that FIFO has slightly higher overhead compared to LIFO,
105130 // but it helps closing idle connections faster reducing the pool size.
106131 PoolFIFO bool
107- // Base number of socket connections.
132+
133+ // PoolSize is the base number of socket connections.
108134 // Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
109135 // If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize,
110136 // you can limit it through MaxActiveConns
137+ //
138+ // default: 10 * runtime.GOMAXPROCS(0)
111139 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
113142 // are busy before returning an error.
114- // Default is ReadTimeout + 1 second.
143+ //
144+ // default: ReadTimeout + 1 second
115145 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
119151 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
122157 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.
124160 // 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.
125162 MaxActiveConns int
163+
126164 // ConnMaxIdleTime is the maximum amount of time a connection may be idle.
127165 // Should be less than server's timeout.
128166 //
129167 // Expired connections may be closed lazily before reuse.
130168 // If d <= 0, connections are not closed due to a connection's idle time.
169+ // -1 disables idle timeout check.
131170 //
132- // Default is 30 minutes. -1 disables idle timeout check.
171+ // default: 30 minutes
133172 ConnMaxIdleTime time.Duration
173+
134174 // ConnMaxLifetime is the maximum amount of time a connection may be reused.
135175 //
136176 // Expired connections may be closed lazily before reuse.
137177 // If <= 0, connections are not closed due to a connection's age.
138178 //
139- // Default is to not close idle connections.
179+ // default: 0
140180 ConnMaxLifetime time.Duration
141181
142- // TLS Config to use. When set, TLS will be negotiated.
182+ // TLSConfig to use. When set, TLS will be negotiated.
143183 TLSConfig * tls.Config
144184
145185 // Limiter interface used to implement circuit breaker or rate limiter.
146186 Limiter Limiter
147187
148- // Enables read only queries on slave/follower nodes.
188+ // readOnly enables read only queries on slave/follower nodes.
149189 readOnly bool
150190
151- // Disable set-lib on connect. Default is false.
191+ // DisableIndentity set-lib on connect. Default is false.
152192 DisableIndentity bool
153193
154- // Add suffix to client name. Default is empty .
194+ // IdentitySuffix - add suffix to client name.
155195 IdentitySuffix string
156196
157197 // 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
158199 UnstableResp3 bool
159200}
160201
0 commit comments