Skip to content

Redis Client Configuration

springboot-data-redis

private int database = 0;
private String url;
private String host = "localhost";
private int port = 6379;
private String username;
private String password;
private boolean ssl;
private Duration timeout;
private Duration connectTimeout;
private String clientName;
private ClientType clientType;

// public static enum ClientType {
//    LETTUCE,
//    JEDIS;
// }
private Sentinel sentinel;
private Cluster cluster;
private final Jedis jedis = new Jedis();
private final Lettuce lettuce = new Lettuce();

Sentinel

private String master;
private List<String> nodes;
private String username;
private String password;

sentinel.master sentinel.nodes sentinel.username sentinel.password

cluster

private List<String> nodes;
private Integer maxRedirects;

cluster.nodes cluster.maxRedirects

Pool

private Boolean enabled;
private int maxIdle = 8;
private int minIdle = 0;
private int maxActive = 8;
private Duration maxWait = Duration.ofMillis(-1L);
private Duration timeBetweenEvictionRuns;

jedis

private final Pool pool = new Pool();
jedis.pool.enabled
jedis.pool.maxIdle
jedis.pool.minIdle
jedis.pool.maxActive
jedis.pool.maxWait
jedis.pool.timeBetweenEvictionRuns

lettuce

private Duration shutdownTimeout = Duration.ofMillis(100L);
private final Pool pool = new Pool();
private final Cluster cluster = new Cluster();

Cluster

private final Refresh refresh = new Refresh();

Refresh

private boolean dynamicRefreshSources = true;
private Duration period;
private boolean adaptive;

Lettuce










lettuce.pool.enabled lettuce.pool.maxIdle lettuce.pool.minIdle lettuce.pool.maxActive lettuce.pool.maxWait lettuce.pool.timeBetweenEvictionRuns lettuce.shutdownTimeout 100 lettuce.cluster.refresh.dynamicRefreshSources true lettuce.cluster.refresh.period lettuce.cluster.refresh.adaptive

Redisson

BaseConfig idleConnectionTimeout connectTimeout timeout retryAttempts retryInterval password username subscriptionsPerConnection clientName sslEnableEndpointIdentification sslProvider sslTruststore sslTruststorePassword sslKeystore sslKeystorePassword sslProtocols pingConnectionInterval keepAlive tcpNoDelay nameMapper

SingleServerConfig address subscriptionConnectionMinimumIdleSize subscriptionConnectionPoolSize connectionMinimumIdleSize connectionPoolSize database dnsMonitoringInterval

BaseMasterSlaveServersConfig

loadBalancer slaveConnectionMinimumIdleSize slaveConnectionPoolSize failedSlaveReconnectionInterval failedSlaveCheckInterval masterConnectionMinimumIdleSize masterConnectionPoolSize readMode

    SLAVE,
    MASTER,
    MASTER_SLAVE;

subscriptionMode

 SLAVE,
    MASTER;

subscriptionConnectionMinimumIdleSize subscriptionConnectionPoolSize dnsMonitoringInterval

SentinelServersConfig

sentinelAddresses masterName sentinelUsername sentinelPassword database scanInterval checkSentinelsList checkSlaveStatusWithSyncing sentinelsDiscovery

ClusterServersConfig

natMapper nodeAddresses scanInterval checkSlotsCoverage

go-redis

Base

Dialer creates new network connection and has priority over Network and Addr options.

Dialer func(ctx context.Context, network, addr string) (net.Conn, error)

Hook that is called when new connection is established.

OnConnect func(ctx context.Context, cn *Conn) error

Use the specified Username 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.

Username string

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.

Password string

Maximum number of retries before giving up. Default is 3 retries; -1 (not 0) disables retries.

MaxRetries int

Minimum backoff between each retry. Default is 8 milliseconds; -1 disables backoff.

MinRetryBackoff time.Duration

Maximum backoff between each retry. Default is 512 milliseconds; -1 disables backoff.

MaxRetryBackoff time.Duration

Dial timeout for establishing new connections. Default is 5 seconds.

DialTimeout time.Duration

Timeout for socket reads. If reached, commands will fail with a timeout instead of blocking. Use value -1 for no timeout and 0 for default. Default is 3 seconds.

ReadTimeout time.Duration

Timeout for socket writes. If reached, commands will fail with a timeout instead of blocking. Default is ReadTimeout.

WriteTimeout time.Duration

Type of connection pool. true for FIFO pool, false for LIFO pool.

Note that fifo has higher overhead compared to lifo. PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO) for sentinel or cluster.

PoolFIFO bool

Maximum number of socket connections. Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.

cluster: // PoolSize applies per cluster node and not for the whole cluster.

 PoolSize int

Minimum number of idle connections which is useful when establishing new connection is slow.

MinIdleConns int

Connection age at which client retires (closes) the connection. Default is to not close aged connections.

MaxConnAge time.Duration

Amount of time client waits for connection if all connections are busy before returning an error. Default is ReadTimeout + 1 second.

PoolTimeout time.Duration

Amount of time after which client closes idle connections. Should be less than server's timeout. Default is 5 minutes. -1 disables idle timeout check.

IdleTimeout time.Duration

Frequency of idle checks made by idle connections reaper. Default is 1 minute. -1 disables idle connections reaper, but idle connections are still discarded by the client if IdleTimeout is set.

IdleCheckFrequency time.Duration

TLS Config to use. When set TLS will be negotiated.

TLSConfig *tls.Config

Options

The network type, either tcp or unix. Default is tcp.

Network string

host:port address.

Addr string

Database to be selected after connecting to the server.

DB int

Enables read only queries on slave nodes.

readOnly bool

Limiter interface used to implemented circuit breaker or rate limiter.

Limiter Limiter

FailoverOptions

The master name.

MasterName string

A seed list of host:port addresses of sentinel nodes.

SentinelAddrs []string

If specified with SentinelPassword, enables ACL-based authentication (via AUTH <user> <pass>).

SentinelUsername string

Sentinel password from "requirepass <password>" (if enabled) in Sentinel configuration, or, if SentinelUsername is also supplied, used for ACL-based authentication.

SentinelPassword string

Allows routing read-only commands to the closest master or slave node. This option only works with NewFailoverClusterClient.

RouteByLatency bool

Allows routing read-only commands to the random master or slave node. This option only works with NewFailoverClusterClient.

RouteRandomly bool

Route all commands to slave read-only nodes.

SlaveOnly bool

Use slaves disconnected with master when cannot get connected slaves Now, this option only works in RandomSlaveAddr function.

UseDisconnectedSlaves bool

Database to be selected after connecting to the server.

DB int

ClusterOptions

A seed list of host:port addresses of cluster nodes.

Addrs []string

NewClient creates a cluster node client with provided name and options.

NewClient func(opt *Options) *Client

The maximum number of retries before giving up. Command is retried on network errors and MOVED/ASK redirects. Default is 3 retries.

MaxRedirects int

Enables read-only commands on slave nodes.

ReadOnly bool

Allows routing read-only commands to the closest master or slave node. It automatically enables ReadOnly.

RouteByLatency bool

Allows routing read-only commands to the random master or slave node. It automatically enables ReadOnly.

RouteRandomly bool

Optional function that returns cluster slots information. It is useful to manually create cluster of standalone Redis servers and load-balance read/write operations between master and slaves. It can use service like ZooKeeper to maintain configuration information and Cluster.ReloadState to manually trigger state reloading.

ClusterSlots func(context.Context) ([]ClusterSlot, error)