Class LettuceConnectionFactory
- All Implemented Interfaces:
DisposableBean,InitializingBean,Lifecycle,Phased,SmartLifecycle,PersistenceExceptionTranslator,ReactiveRedisConnectionFactory,RedisConnectionFactory
Connection factory creating Lettuce-based
connections.
This factory creates a new LettuceConnection on each call to getConnection(). While multiple
LettuceConnections share a single thread-safe native connection by default, LettuceConnection and its
clustered variant are not Thread-safe and instances should not be shared across
threads.
The shared native connection is never closed by LettuceConnection, therefore it is not validated by default
on getConnection(). Use setValidateConnection(boolean) to change this behavior if necessary. If
shareNativeConnection is true, a shared connection will be used for regular operations and a
LettuceConnectionProvider will be used to select a connection for blocking and tx operations only, which
should not share a connection. If native connection sharing is disabled, new (or pooled) connections will be used for
all operations.
LettuceConnectionFactory should be configured using an environmental configuration and the
client configuration. Lettuce supports the following environmental configurations:
RedisStandaloneConfigurationRedisStaticMasterReplicaConfigurationRedisSocketConfigurationRedisSentinelConfigurationRedisClusterConfiguration
This connection factory implements InitializingBean and SmartLifecycle for flexible lifecycle
control. It must be initialized and started before you can obtain a
connection. Initialization starts this bean
early by default. You can Lifecycle.stop() and restart this connection factory if needed. Disabling early startup leaves lifecycle
management to the container refresh if auto-startup is enabled.
- Author:
- Costin Leau, Jennifer Hickey, Thomas Darimont, Christoph Strobl, Mark Paluch, Balázs Németh, Ruben Cervilla, Luis De Bello, Andrea Como, Chris Bono, John Blum, Zhian Chen, UHyeon Jeong
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newLettuceConnectionFactoryinstance with default settings.LettuceConnectionFactory(String host, int port) Constructs a newLettuceConnectionFactoryinstance with default settings.LettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisClusterConfigurationapplied to create aRedisClusterClient.LettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisClusterConfigurationandLettuceClientConfiguration.LettuceConnectionFactory(RedisConfiguration redisConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisSocketConfiguration.LettuceConnectionFactory(RedisConfiguration redisConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisStaticMasterReplicaConfigurationandLettuceClientConfiguration.LettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisSentinelConfiguration.LettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisSentinelConfigurationandLettuceClientConfiguration.LettuceConnectionFactory(RedisStandaloneConfiguration configuration) Constructs a newLettuceConnectionFactoryinstance with default settings.LettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisStandaloneConfigurationandLettuceClientConfiguration. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected io.lettuce.core.AbstractRedisClientstatic RedisConfigurationcreateRedisConfiguration(io.lettuce.core.RedisURI redisUri) Creates aRedisConfigurationbased on aRedisURIaccording to the following: IfRedisURIcontains sentinels, aRedisSentinelConfigurationis returned IfRedisURIhas a configured socket aRedisSocketConfigurationis returned Otherwise aRedisStandaloneConfigurationis returnedstatic RedisConfigurationcreateRedisConfiguration(String redisUri) Creates aRedisConfigurationbased on aURIaccording to the following: IfredisUricontains sentinels, aRedisSentinelConfigurationis returned IfredisUrihas a configured socket aRedisSocketConfigurationis returned Otherwise aRedisStandaloneConfigurationis returnedvoiddestroy()protected LettuceConnectionProviderdoCreateConnectionProvider(io.lettuce.core.AbstractRedisClient client, io.lettuce.core.codec.RedisCodec<?, ?> codec) protected LettuceClusterConnectiondoCreateLettuceClusterConnection(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, ClusterTopologyProvider topologyProvider, ClusterCommandExecutor clusterCommandExecutor, Duration commandTimeout) Customization hook forLettuceClusterConnectioncreation.protected LettuceConnectiondoCreateLettuceConnection(io.lettuce.core.api.StatefulRedisConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, long timeout, int database) Customization hook forLettuceConnectioncreation.Returns the client name.io.lettuce.core.resource.ClientResourcesGet theClientResourcesto reuse infrastructure.Returns a suitableconnectionfor interacting with Redis Cluster.Returns a suitableconnectionfor interacting with Redis.booleanSpecifies if pipelined results should be converted to the expected data type.intReturns the index of the database.booleanIndicatesshared connectionsshould be eagerly initialized.Returns the current host.io.lettuce.core.AbstractRedisClientReturns the nativeAbstractRedisClientused by this instance.Returns the password used for authenticating with the Redis server.intgetPhase()intgetPort()Returns the current port.org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisClusterConnectionorg.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnectionio.lettuce.core.AbstractRedisClientReturns the nativeAbstractRedisClientused by this instance.Returns a suitableconnectionfor interacting with Redis Sentinel.protected io.lettuce.core.cluster.api.StatefulRedisClusterConnection<byte[],byte[]> protected io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> protected io.lettuce.core.api.StatefulConnection<ByteBuffer,ByteBuffer> booleanIndicates if multipleLettuceConnections should share a single native connection.longReturns the shutdown timeout for shutting down the RedisClient (in milliseconds).longReturns the connection timeout (in milliseconds).booleanIndicates if validation of the native Lettuce connection is enabled.voidInitialize the shared connection ifnative connection sharingis enabled and reset any previously existing connection.booleanbooleanbooleanbooleanbooleanbooleanReturns whether to issue a StartTLS.booleanisUseSsl()Returns whether to use SSL.booleanDeprecated.voidReset the underlying shared Connection, to be reinitialized on next access.voidsetAutoStartup(boolean autoStartup) Configure if this Lifecycle connection factory should get started automatically by the container at the time that the containing ApplicationContext gets refreshed.voidsetClientName(String clientName) Deprecated.configure the client name usingLettuceClientConfiguration.voidsetClientResources(io.lettuce.core.resource.ClientResources clientResources) Deprecated.since 2.0, configureClientResourcesusingLettuceClientConfiguration.voidsetConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) Specifies if pipelined and transaction results should be converted to the expected data type.voidsetDatabase(int index) Deprecated.since 3.2, configure the database index usingRedisStandaloneConfiguration,RedisSocketConfiguration,RedisSentinelConfiguration, orRedisStaticMasterReplicaConfiguration.voidsetEagerInitialization(boolean eagerInitialization) Enables eager initialization ofshared connections.voidsetEarlyStartup(boolean earlyStartup) Configure if this InitializingBean's component Lifecycle should get started early byafterPropertiesSet()at the time that the bean is initialized.voidsetExecutor(AsyncTaskExecutor executor) Configures theexecutorused to execute commands asynchronously across the cluster.voidsetHostName(String hostName) Deprecated.since 2.0, configure the hostname usingRedisStandaloneConfiguration.voidsetPassword(String password) Deprecated.since 2.0, configure the password usingRedisStandaloneConfiguration,RedisSentinelConfigurationorRedisClusterConfiguration.voidsetPhase(int phase) Specify the lifecycle phase for pausing and resuming this executor.voidsetPipeliningFlushPolicy(LettuceConnection.PipeliningFlushPolicy pipeliningFlushPolicy) Configures the flushing policy when using pipelining.voidsetPort(int port) Deprecated.since 2.0, configure the port usingRedisStandaloneConfiguration.voidsetShareNativeConnection(boolean shareNativeConnection) Enables multipleLettuceConnections to share a single native connection.voidsetShutdownTimeout(long shutdownTimeout) Deprecated.since 2.0, configure the shutdown timeout usingLettuceClientConfiguration.voidsetStartTls(boolean startTls) Deprecated.since 2.0, configure StartTLS usingLettuceClientConfiguration.voidsetTimeout(long timeout) Deprecated.since 2.0, configure the timeout usingLettuceClientConfiguration.voidsetUseSsl(boolean useSsl) Deprecated.since 2.0, configure SSL usage usingLettuceClientConfiguration.voidsetValidateConnection(boolean validateConnection) Enables validation of the shared native Lettuce connection on calls togetConnection().voidsetVerifyPeer(boolean verifyPeer) Deprecated.since 2.0, configure peer verification usingLettuceClientConfiguration.voidstart()voidstop()voidValidate the shared connections and reinitialize if invalid.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Constructor Details
-
LettuceConnectionFactory
public LettuceConnectionFactory()Constructs a newLettuceConnectionFactoryinstance with default settings. -
LettuceConnectionFactory
Constructs a newLettuceConnectionFactoryinstance with default settings. -
LettuceConnectionFactory
Constructs a newLettuceConnectionFactoryinstance using the givenRedisSocketConfiguration.- Parameters:
redisConfiguration- must not be null.- Since:
- 2.1
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisConfiguration redisConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisStaticMasterReplicaConfigurationandLettuceClientConfiguration.- Parameters:
redisConfiguration- must not be null.clientConfiguration- must not be null.- Since:
- 2.1
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactoryinstance using the givenRedisClusterConfigurationapplied to create aRedisClusterClient.- Parameters:
clusterConfiguration- must not be null.- Since:
- 1.7
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisClusterConfigurationandLettuceClientConfiguration.- Parameters:
clusterConfiguration- must not be null.clientConfiguration- must not be null.- Since:
- 2.0
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactoryinstance using the givenRedisSentinelConfiguration.- Parameters:
sentinelConfiguration- must not be null.- Since:
- 1.6
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisSentinelConfigurationandLettuceClientConfiguration.- Parameters:
sentinelConfiguration- must not be null.clientConfiguration- must not be null.- Since:
- 2.0
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactoryinstance with default settings. -
LettuceConnectionFactory
public LettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactoryinstance using the givenRedisStandaloneConfigurationandLettuceClientConfiguration.- Parameters:
standaloneConfiguration- must not be null.clientConfiguration- must not be null.- Since:
- 2.0
-
-
Method Details
-
createRedisConfiguration
Creates aRedisConfigurationbased on aURIaccording to the following:- If
redisUricontains sentinels, aRedisSentinelConfigurationis returned - If
redisUrihas a configured socket aRedisSocketConfigurationis returned - Otherwise a
RedisStandaloneConfigurationis returned
- Parameters:
redisUri- the connection URI in the format of aRedisURI.- Returns:
- an appropriate
RedisConfigurationinstance representing the Redis URI. - Since:
- 2.5.3
- See Also:
-
createRedisConfiguration(RedisURI)RedisURI
- If
-
createRedisConfiguration
Creates aRedisConfigurationbased on aRedisURIaccording to the following:- If
RedisURIcontains sentinels, aRedisSentinelConfigurationis returned - If
RedisURIhas a configured socket aRedisSocketConfigurationis returned - Otherwise a
RedisStandaloneConfigurationis returned
- Parameters:
redisUri- the connection URI.- Returns:
- an appropriate
RedisConfigurationinstance representing the Redis URI. - Since:
- 2.5.3
- See Also:
-
RedisURI
- If
-
setExecutor
Configures theexecutorused to execute commands asynchronously across the cluster.- Parameters:
executor-executorused to execute commands asynchronously across the cluster.- Since:
- 3.2
-
getHostName
Returns the current host.- Returns:
- the host.
-
setHostName
Deprecated.since 2.0, configure the hostname usingRedisStandaloneConfiguration.Sets the hostname.- Parameters:
hostName- the hostname to set.
-
getPort
public int getPort()Returns the current port.- Returns:
- the port.
-
setPort
Deprecated.since 2.0, configure the port usingRedisStandaloneConfiguration.Sets the port.- Parameters:
port- the port to set.
-
setPipeliningFlushPolicy
Configures the flushing policy when using pipelining. If not set, defaults toflush on each command.- Parameters:
pipeliningFlushPolicy- the flushing policy to control when commands get written to the Redis connection.- Since:
- 2.3
- See Also:
-
LettuceConnection.openPipeline()StatefulConnection.flushCommands()
-
getTimeout
public long getTimeout()Returns the connection timeout (in milliseconds).- Returns:
- connection timeout.
-
setTimeout
Deprecated.since 2.0, configure the timeout usingLettuceClientConfiguration.Sets the connection timeout (in milliseconds).- Parameters:
timeout- the timeout.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.
-
isUseSsl
public boolean isUseSsl()Returns whether to use SSL.- Returns:
- use of SSL.
-
setUseSsl
Deprecated.since 2.0, configure SSL usage usingLettuceClientConfiguration.Sets to use SSL connection.- Parameters:
useSsl- true to use SSL.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.
-
isVerifyPeer
Deprecated.since 3.4, useLettuceClientConfiguration.getVerifyMode()instead.Returns whether to verify certificate validity/hostname check when SSL is used.- Returns:
- whether to verify peers when using SSL.
-
setVerifyPeer
Deprecated.since 2.0, configure peer verification usingLettuceClientConfiguration.Sets to use verify certificate validity/hostname check when SSL is used.- Parameters:
verifyPeer- false not to verify hostname.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.
-
isStartTls
public boolean isStartTls()Returns whether to issue a StartTLS.- Returns:
- use of StartTLS.
-
setStartTls
Deprecated.since 2.0, configure StartTLS usingLettuceClientConfiguration.Sets to issue StartTLS.- Parameters:
startTls- true to issue StartTLS.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.
-
getValidateConnection
public boolean getValidateConnection()Indicates if validation of the native Lettuce connection is enabled.- Returns:
- connection validation enabled.
-
setValidateConnection
public void setValidateConnection(boolean validateConnection) Enables validation of the shared native Lettuce connection on calls togetConnection(). A new connection will be created and used if validation fails.Lettuce will automatically reconnect until close is called, which should never happen through
LettuceConnectionif a shared native connection is used, therefore the default is false.Setting this to true will result in a round-trip call to the server on each new connection, so this setting should only be used if connection sharing is enabled and there is code that is actively closing the native Lettuce connection.
- Parameters:
validateConnection- enable connection validation.
-
getEagerInitialization
public boolean getEagerInitialization()Indicatesshared connectionsshould be eagerly initialized. Eager initialization requires a running Redis instance duringstartupto allow early validation of connection factory configuration. Eager initialization also prevents blocking connect while using reactive API and is recommended for reactive API usage. -
setEagerInitialization
public void setEagerInitialization(boolean eagerInitialization) Enables eager initialization ofshared connections.- Parameters:
eagerInitialization- enable eager connection shared connection initialization uponafterPropertiesSet().- Since:
- 2.2
-
getDatabase
public int getDatabase()Returns the index of the database.- Returns:
- the database index.
-
setDatabase
Deprecated.since 3.2, configure the database index usingRedisStandaloneConfiguration,RedisSocketConfiguration,RedisSentinelConfiguration, orRedisStaticMasterReplicaConfiguration.Sets the index of the database used by this connection factory. Default is 0.- Parameters:
index- database index.
-
getClientName
Returns the client name.- Returns:
- the client name or null if not set.
- Since:
- 2.1
-
setClientName
Deprecated.configure the client name usingLettuceClientConfiguration.Sets the client name used by this connection factory.- Parameters:
clientName- the client name. Can be null.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.- Since:
- 2.1
-
getNativeClient
Returns the nativeAbstractRedisClientused by this instance. The client is initialized as part ofthe bean initialization lifecycleand only available when this connection factory is initialized.Depending on the configuration, the client can be either
RedisClientorRedisClusterClient.- Returns:
- the native
AbstractRedisClient. Can be null if not initialized. - Since:
- 2.5
- See Also:
-
getRequiredNativeClient
public io.lettuce.core.AbstractRedisClient getRequiredNativeClient()Returns the nativeAbstractRedisClientused by this instance. The client is initialized as part ofthe bean initialization lifecycleand only available when this connection factory is initialized. ThrowsIllegalStateExceptionif not yet initialized.Depending on the configuration, the client can be either
RedisClientorRedisClusterClient.- Returns:
- the native
AbstractRedisClient. - Throws:
IllegalStateException- if not yet initialized.- Since:
- 2.5
- See Also:
-
getPassword
Returns the password used for authenticating with the Redis server.- Returns:
- password for authentication or null if not set.
-
setPassword
Deprecated.since 2.0, configure the password usingRedisStandaloneConfiguration,RedisSentinelConfigurationorRedisClusterConfiguration.Sets the password used for authenticating with the Redis server.- Parameters:
password- the password to set
-
getShutdownTimeout
public long getShutdownTimeout()Returns the shutdown timeout for shutting down the RedisClient (in milliseconds).- Returns:
- shutdown timeout.
- Since:
- 1.6
-
setShutdownTimeout
Deprecated.since 2.0, configure the shutdown timeout usingLettuceClientConfiguration.Sets the shutdown timeout for shutting down the RedisClient (in milliseconds).- Parameters:
shutdownTimeout- the shutdown timeout.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.- Since:
- 1.6
-
getClientResources
Get theClientResourcesto reuse infrastructure.- Returns:
- null if not set.
- Since:
- 1.7
-
setClientResources
@Deprecated public void setClientResources(io.lettuce.core.resource.ClientResources clientResources) Deprecated.since 2.0, configureClientResourcesusingLettuceClientConfiguration.Sets theClientResourcesto reuse the client infrastructure.
Set to null to not share resources.- Parameters:
clientResources- can be null.- Throws:
IllegalStateException- ifLettuceClientConfigurationis immutable.- Since:
- 1.7
-
getClientConfiguration
- Returns:
- the
LettuceClientConfiguration. - Since:
- 2.0
-
getStandaloneConfiguration
- Returns:
- the
RedisStandaloneConfiguration. - Since:
- 2.0
-
getSocketConfiguration
- Returns:
- the
RedisSocketConfigurationor null if not set. - Since:
- 2.1
-
getSentinelConfiguration
- Returns:
- the
RedisSentinelConfiguration, may be null. - Since:
- 2.0
-
getClusterConfiguration
- Returns:
- the
RedisClusterConfiguration, may be null. - Since:
- 2.0
-
getPhase
public int getPhase()- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
setPhase
public void setPhase(int phase) Specify the lifecycle phase for pausing and resuming this executor. The default is0.- Since:
- 3.2
- See Also:
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle- Since:
- 3.3
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) Configure if this Lifecycle connection factory should get started automatically by the container at the time that the containing ApplicationContext gets refreshed.This connection factory defaults to early auto-startup during
afterPropertiesSet()and can potentially create Redis connections early on in the lifecycle. SeesetEarlyStartup(boolean)for delaying connection creation to the ApplicationContext refresh if auto-startup is enabled.- Parameters:
autoStartup- true to automaticallystart()the connection factory; false otherwise.- Since:
- 3.3
- See Also:
-
isEarlyStartup
public boolean isEarlyStartup()- Returns:
- whether to
start()the component duringafterPropertiesSet(). - Since:
- 3.3
-
setEarlyStartup
public void setEarlyStartup(boolean earlyStartup) Configure if this InitializingBean's component Lifecycle should get started early byafterPropertiesSet()at the time that the bean is initialized. The component defaults to auto-startup.This method is related to
auto-startupand can be used to delay Redis client startup until the ApplicationContext refresh. Disabling early startup does not disable auto-startup.- Parameters:
earlyStartup- true to earlystart()the component; false otherwise.- Since:
- 3.3
- See Also:
-
getConvertPipelineAndTxResults
public boolean getConvertPipelineAndTxResults()Specifies if pipelined results should be converted to the expected data type. Iffalse, results ofLettuceConnection.closePipeline()and {LettuceConnection#exec()} will be of the type returned by the Lettuce driver.- Specified by:
getConvertPipelineAndTxResultsin interfaceRedisConnectionFactory- Returns:
trueto convert pipeline and transaction results;falseotherwise.
-
setConvertPipelineAndTxResults
public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) Specifies if pipelined and transaction results should be converted to the expected data type. Iffalse, results ofLettuceConnection.closePipeline()and {LettuceConnection#exec()} will be of the type returned by the Lettuce driver.- Parameters:
convertPipelineAndTxResults-trueto convert pipeline and transaction results;falseotherwise.
-
isRedisSentinelAware
public boolean isRedisSentinelAware()- Returns:
- true when
RedisSentinelConfigurationis present. - Since:
- 1.5
-
isClusterAware
public boolean isClusterAware()- Returns:
- true when
RedisClusterConfigurationis present. - Since:
- 1.7
-
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning() -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-
getConnection
Description copied from interface:RedisConnectionFactoryReturns a suitableconnectionfor interacting with Redis.- Specified by:
getConnectionin interfaceRedisConnectionFactory- Returns:
connectionfor interacting with Redis.
-
getClusterConnection
Description copied from interface:RedisConnectionFactoryReturns a suitableconnectionfor interacting with Redis Cluster.- Specified by:
getClusterConnectionin interfaceRedisConnectionFactory- Returns:
- a
connectionfor interacting with Redis Cluster.
-
getSentinelConnection
Description copied from interface:RedisConnectionFactoryReturns a suitableconnectionfor interacting with Redis Sentinel.- Specified by:
getSentinelConnectionin interfaceRedisConnectionFactory- Returns:
- a
connectionfor interacting with Redis Sentinel.
-
doCreateLettuceConnection
protected LettuceConnection doCreateLettuceConnection(@Nullable io.lettuce.core.api.StatefulRedisConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, long timeout, int database) Customization hook forLettuceConnectioncreation.- Parameters:
sharedConnection- the sharedStatefulRedisConnectionifgetShareNativeConnection()is true; null otherwise.connectionProvider- theLettuceConnectionProviderto release connections.timeout- command timeout inTimeUnit.MILLISECONDS.database- database index to operate on.- Returns:
- the
LettuceConnection. - Throws:
IllegalArgumentException- if a required parameter is null.- Since:
- 2.2
-
doCreateLettuceClusterConnection
protected LettuceClusterConnection doCreateLettuceClusterConnection(@Nullable io.lettuce.core.cluster.api.StatefulRedisClusterConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, ClusterTopologyProvider topologyProvider, ClusterCommandExecutor clusterCommandExecutor, Duration commandTimeout) Customization hook forLettuceClusterConnectioncreation.- Parameters:
sharedConnection- the sharedStatefulRedisConnectionifgetShareNativeConnection()is true; null otherwise.connectionProvider- theLettuceConnectionProviderto release connections.topologyProvider- theClusterTopologyProvider.clusterCommandExecutor- theClusterCommandExecutorto release connections.commandTimeout- command timeoutDuration.- Returns:
- the
LettuceConnection. - Throws:
IllegalArgumentException- if a required parameter is null.- Since:
- 2.2
-
getReactiveConnection
public org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnection getReactiveConnection()- Specified by:
getReactiveConnectionin interfaceReactiveRedisConnectionFactory- Returns:
- a reactive Redis connection.
-
getReactiveClusterConnection
public org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisClusterConnection getReactiveClusterConnection()- Specified by:
getReactiveClusterConnectionin interfaceReactiveRedisConnectionFactory- Returns:
- a reactive Redis Cluster connection.
-
initConnection
public void initConnection()Initialize the shared connection ifnative connection sharingis enabled and reset any previously existing connection. -
resetConnection
public void resetConnection()Reset the underlying shared Connection, to be reinitialized on next access. -
validateConnection
public void validateConnection()Validate the shared connections and reinitialize if invalid. -
translateExceptionIfPossible
- Specified by:
translateExceptionIfPossiblein interfacePersistenceExceptionTranslator
-
doCreateConnectionProvider
protected LettuceConnectionProvider doCreateConnectionProvider(io.lettuce.core.AbstractRedisClient client, io.lettuce.core.codec.RedisCodec<?, ?> codec) Create aLettuceConnectionProvidergivenAbstractRedisClientandRedisCodec. Configuration of this connection factory specifies the type of the created connection provider. This method creates either aLettuceConnectionProviderfor eitherRedisClientorRedisClusterClient. Subclasses may override this method to decorate the connection provider.- Parameters:
client- eitherRedisClientorRedisClusterClient, must not be null.codec- used for connection creation, must not be null. By default, abyte[]codec. Reactive connections require aByteBuffercodec.- Returns:
- the connection provider.
- Since:
- 2.1
-
createClient
protected io.lettuce.core.AbstractRedisClient createClient()
-
LettuceClientConfiguration.getVerifyMode()instead.