Documentation
¶
Index ¶
- func New(opts ...Option) *redis.Client
- type Option
- func WithAddr(addr string) Option
- func WithClientName(clientName string) Option
- func WithConnMaxIdleTime(connMaxIdleTime time.Duration) Option
- func WithConnMaxLifetime(connMaxLifetime time.Duration) Option
- func WithContextTimeoutEnabled(contextTimeoutEnabled bool) Option
- func WithCredentialsProvider(credentialsProvider func() (username string, password string)) Option
- func WithCredentialsProviderContext(...) Option
- func WithDB(db int) Option
- func WithDialTimeout(dialTimeout time.Duration) Option
- func WithDialer(dialer func(ctx context.Context, network, addr string) (net.Conn, error)) Option
- func WithDisableIdentity(disableIdentity bool) Option
- func WithFailingTimeoutSeconds(failingTimeoutSeconds int) Option
- func WithIdentitySuffix(identitySuffix string) Option
- func WithLimiter(limiter redis.Limiter) Option
- func WithMaxActiveConns(maxActiveConns int) Option
- func WithMaxIdleConns(maxIdleConns int) Option
- func WithMaxRetries(maxRetries int) Option
- func WithMaxRetryBackoff(maxRetryBackoff time.Duration) Option
- func WithMinIdleConns(minIdleConns int) Option
- func WithMinRetryBackoff(minRetryBackoff time.Duration) Option
- func WithNetwork(network string) Option
- func WithOnConnect(onConnect func(ctx context.Context, cn *redis.Conn) error) Option
- func WithPassword(password string) Option
- func WithPoolFIFO(poolFIFO bool) Option
- func WithPoolSize(poolSize int) Option
- func WithPoolTimeout(poolTimeout time.Duration) Option
- func WithProtocol(protocol int) Option
- func WithReadBufferSize(readBufferSize int) Option
- func WithReadTimeout(readTimeout time.Duration) Option
- func WithStreamingCredentialsProvider(streamingCredentialsProvider auth.StreamingCredentialsProvider) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithUnstableResp3(unstableResp3 bool) Option
- func WithUsername(username string) Option
- func WithWriteBufferSize(writeBufferSize int) Option
- func WithWriteTimeout(writeTimeout time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
func WithClientName ¶
ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
func WithConnMaxIdleTime ¶
ConnMaxIdleTime is the maximum amount of time a connection may be idle. Should be less than server's timeout.
Expired connections may be closed lazily before reuse. If d <= 0, connections are not closed due to a connection's idle time. -1 disables idle timeout check.
default: 30 minutes
func WithConnMaxLifetime ¶
ConnMaxLifetime is the maximum amount of time a connection may be reused.
Expired connections may be closed lazily before reuse. If <= 0, connections are not closed due to a connection's age.
default: 0
func WithContextTimeoutEnabled ¶
ContextTimeoutEnabled controls whether the client respects context timeouts and deadlines. See https://redis.uptrace.dev/guide/go-redis-debugging.html#timeouts
func WithCredentialsProvider ¶
CredentialsProvider allows the username and password to be updated before reconnecting. It should return the current username and password.
func WithCredentialsProviderContext ¶
func WithCredentialsProviderContext(credentialsProviderContext func(ctx context.Context) (username string, password string, err error)) Option
CredentialsProviderContext is an enhanced parameter of CredentialsProvider, done to maintain API compatibility. In the future, there might be a merge between CredentialsProviderContext and CredentialsProvider. There will be a conflict between them; if CredentialsProviderContext exists, we will ignore CredentialsProvider.
func WithDialer ¶
Dialer creates new network connection and has priority over Network and Addr options.
func WithDisableIdentity ¶
DisableIdentity is used to disable CLIENT SETINFO command on connect.
default: false
func WithFailingTimeoutSeconds ¶
FailingTimeoutSeconds is the timeout in seconds for marking a cluster node as failing. When a node is marked as failing, it will be avoided for this duration. Default is 15 seconds.
func WithIdentitySuffix ¶
Add suffix to client name. Default is empty. IdentitySuffix - add suffix to client name.
func WithLimiter ¶
Limiter interface used to implement circuit breaker or rate limiter.
func WithMaxActiveConns ¶
MaxActiveConns is the maximum number of connections allocated by the pool at a given time. When zero, there is no limit on the number of connections in the pool. If the pool is full, the next call to Get() will block until a connection is released.
func WithMaxIdleConns ¶
MaxIdleConns is the maximum number of idle connections. The idle connections are not closed by default.
default: 0
func WithMaxRetries ¶
MaxRetries is the maximum number of retries before giving up. -1 (not 0) disables retries.
default: 3 retries
func WithMaxRetryBackoff ¶
MaxRetryBackoff is the maximum backoff between each retry. -1 disables backoff. default: 512 milliseconds;
func WithMinIdleConns ¶
MinIdleConns is the minimum number of idle connections which is useful when establishing new connection is slow. The idle connections are not closed by default.
default: 0
func WithMinRetryBackoff ¶
MinRetryBackoff is the minimum backoff between each retry. -1 disables backoff.
default: 8 milliseconds
func WithOnConnect ¶
Hook that is called when new connection is established.
func WithPassword ¶
Password is an optional password. Must match the password specified in the `requirepass` server configuration option (if connecting to a Redis 5.0 instance, or lower), or the User Password when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
func WithPoolFIFO ¶
PoolFIFO type of connection pool.
- true for FIFO pool
- false for LIFO pool.
Note that FIFO has slightly higher overhead compared to LIFO, but it helps closing idle connections faster reducing the pool size.
func WithPoolSize ¶
PoolSize is the base number of socket connections. Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS. If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize, you can limit it through MaxActiveConns
default: 10 * runtime.GOMAXPROCS(0)
func WithPoolTimeout ¶
PoolTimeout is the amount of time client waits for connection if all connections are busy before returning an error.
default: ReadTimeout + 1 second
func WithProtocol ¶
Protocol 2 or 3. Use the version to negotiate RESP version with redis-server.
default: 3.
func WithReadBufferSize ¶
ReadBufferSize is the size of the bufio.Reader buffer for each connection. Larger buffers can improve performance for commands that return large responses. Smaller buffers can improve memory usage for larger pools.
default: 32KiB (32768 bytes)
func WithReadTimeout ¶
ReadTimeout for socket reads. If reached, commands will fail with a timeout instead of blocking. Supported values:
- `-1` - no timeout (block indefinitely).
- `-2` - disables SetReadDeadline calls completely.
default: 3 seconds
func WithStreamingCredentialsProvider ¶
func WithStreamingCredentialsProvider(streamingCredentialsProvider auth.StreamingCredentialsProvider) Option
StreamingCredentialsProvider is used to retrieve the credentials for the connection from an external source. Those credentials may change during the connection lifetime. This is useful for managed identity scenarios where the credentials are retrieved from an external source.
Currently, this is a placeholder for the future implementation.
func WithTLSConfig ¶
TLSConfig to use. When set, TLS will be negotiated.
func WithUnstableResp3 ¶
UnstableResp3 enables Unstable mode for Redis Search module with RESP3. When unstable mode is enabled, the client will use RESP3 protocol and only be able to use RawResult
func WithUsername ¶
Username is used to authenticate the current connection with one of the connections defined in the ACL list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
func WithWriteBufferSize ¶
WriteBufferSize is the size of the bufio.Writer buffer for each connection. Larger buffers can improve performance for large pipelines and commands with many arguments. Smaller buffers can improve memory usage for larger pools.
default: 32KiB (32768 bytes)
func WithWriteTimeout ¶
WriteTimeout for socket writes. If reached, commands will fail with a timeout instead of blocking. Supported values:
- `-1` - no timeout (block indefinitely).
- `-2` - disables SetWriteDeadline calls completely.
default: 3 seconds