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
LettuceConnection
s 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:
RedisStandaloneConfiguration
RedisStaticMasterReplicaConfiguration
RedisSocketConfiguration
RedisSentinelConfiguration
RedisClusterConfiguration
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
by default
. You can Lifecycle.stop()
and restart
this connection factory if needed.
- 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
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionConstructs a newLettuceConnectionFactory
instance with default settings.LettuceConnectionFactory
(String host, int port) Constructs a newLettuceConnectionFactory
instance with default settings.LettuceConnectionFactory
(RedisClusterConfiguration clusterConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisClusterConfiguration
applied to create aRedisClusterClient
.LettuceConnectionFactory
(RedisClusterConfiguration clusterConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisClusterConfiguration
andLettuceClientConfiguration
.LettuceConnectionFactory
(RedisConfiguration redisConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisSocketConfiguration
.LettuceConnectionFactory
(RedisConfiguration redisConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisStaticMasterReplicaConfiguration
andLettuceClientConfiguration
.LettuceConnectionFactory
(RedisSentinelConfiguration sentinelConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisSentinelConfiguration
.LettuceConnectionFactory
(RedisSentinelConfiguration sentinelConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisSentinelConfiguration
andLettuceClientConfiguration
.LettuceConnectionFactory
(RedisStandaloneConfiguration configuration) Constructs a newLettuceConnectionFactory
instance with default settings.LettuceConnectionFactory
(RedisStandaloneConfiguration standaloneConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisStandaloneConfiguration
andLettuceClientConfiguration
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected io.lettuce.core.AbstractRedisClient
static RedisConfiguration
createRedisConfiguration
(io.lettuce.core.RedisURI redisUri) Creates aRedisConfiguration
based on aRedisURI
according to the following: IfRedisURI
contains sentinels, aRedisSentinelConfiguration
is returned IfRedisURI
has a configured socket aRedisSocketConfiguration
is returned Otherwise aRedisStandaloneConfiguration
is returnedstatic RedisConfiguration
createRedisConfiguration
(String redisUri) Creates aRedisConfiguration
based on aURI
according to the following: IfredisUri
contains sentinels, aRedisSentinelConfiguration
is returned IfredisUri
has a configured socket aRedisSocketConfiguration
is returned Otherwise aRedisStandaloneConfiguration
is returnedvoid
destroy()
protected LettuceConnectionProvider
doCreateConnectionProvider
(io.lettuce.core.AbstractRedisClient client, io.lettuce.core.codec.RedisCodec<?, ?> codec) protected LettuceClusterConnection
doCreateLettuceClusterConnection
(io.lettuce.core.cluster.api.StatefulRedisClusterConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, ClusterTopologyProvider topologyProvider, ClusterCommandExecutor clusterCommandExecutor, Duration commandTimeout) Customization hook forLettuceClusterConnection
creation.protected LettuceConnection
doCreateLettuceConnection
(io.lettuce.core.api.StatefulRedisConnection<byte[], byte[]> sharedConnection, LettuceConnectionProvider connectionProvider, long timeout, int database) Customization hook forLettuceConnection
creation.Returns the client name.io.lettuce.core.resource.ClientResources
Get theClientResources
to reuse infrastructure.Returns a suitableconnection
for interacting with Redis Cluster.Returns a suitableconnection
for interacting with Redis.boolean
Specifies if pipelined results should be converted to the expected data type.int
Returns the index of the database.boolean
Indicatesshared connections
should be eagerly initialized.Returns the current host.io.lettuce.core.AbstractRedisClient
Returns the nativeAbstractRedisClient
used by this instance.Returns the password used for authenticating with the Redis server.int
getPhase()
int
getPort()
Returns the current port.org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisClusterConnection
org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnection
io.lettuce.core.AbstractRedisClient
Returns the nativeAbstractRedisClient
used by this instance.Returns a suitableconnection
for 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> boolean
Indicates if multipleLettuceConnection
s should share a single native connection.long
Returns the shutdown timeout for shutting down the RedisClient (in milliseconds).long
Returns the connection timeout (in milliseconds).boolean
Indicates if validation of the native Lettuce connection is enabled.void
Initialize the shared connection ifnative connection sharing
is enabled and reset any previously existing connection.boolean
boolean
boolean
boolean
Returns whether to issue a StartTLS.boolean
isUseSsl()
Returns whether to use SSL.boolean
Returns whether to verify certificate validity/hostname check when SSL is used.void
Reset the underlying shared Connection, to be reinitialized on next access.void
setClientName
(String clientName) Deprecated.void
setClientResources
(io.lettuce.core.resource.ClientResources clientResources) Deprecated.since 2.0, configureClientResources
usingLettuceClientConfiguration
.void
setConvertPipelineAndTxResults
(boolean convertPipelineAndTxResults) Specifies if pipelined and transaction results should be converted to the expected data type.void
setDatabase
(int index) Deprecated.since 3.2, configure the database index usingRedisStandaloneConfiguration
,RedisSocketConfiguration
,RedisSentinelConfiguration
, orRedisStaticMasterReplicaConfiguration
.void
setEagerInitialization
(boolean eagerInitialization) Enables eager initialization ofshared connections
.void
setExecutor
(AsyncTaskExecutor executor) Configures theexecutor
used to execute commands asynchronously across the cluster.void
setHostName
(String hostName) Deprecated.since 2.0, configure the hostname usingRedisStandaloneConfiguration
.void
setPassword
(String password) Deprecated.since 2.0, configure the password usingRedisStandaloneConfiguration
,RedisSentinelConfiguration
orRedisClusterConfiguration
.void
setPhase
(int phase) Specify the lifecycle phase for pausing and resuming this executor.void
setPipeliningFlushPolicy
(LettuceConnection.PipeliningFlushPolicy pipeliningFlushPolicy) Configures the flushing policy when using pipelining.void
setPort
(int port) Deprecated.since 2.0, configure the port usingRedisStandaloneConfiguration
.void
setShareNativeConnection
(boolean shareNativeConnection) Enables multipleLettuceConnection
s to share a single native connection.void
setShutdownTimeout
(long shutdownTimeout) Deprecated.since 2.0, configure the shutdown timeout usingLettuceClientConfiguration
.void
setStartTls
(boolean startTls) Deprecated.since 2.0, configure StartTLS usingLettuceClientConfiguration
.void
setTimeout
(long timeout) Deprecated.since 2.0, configure the timeout usingLettuceClientConfiguration
.void
setUseSsl
(boolean useSsl) Deprecated.since 2.0, configure SSL usage usingLettuceClientConfiguration
.void
setValidateConnection
(boolean validateConnection) Enables validation of the shared native Lettuce connection on calls togetConnection()
.void
setVerifyPeer
(boolean verifyPeer) Deprecated.since 2.0, configure peer verification usingLettuceClientConfiguration
.void
start()
void
stop()
void
Validate the shared connections and reinitialize if invalid.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
-
Constructor Details
-
LettuceConnectionFactory
public LettuceConnectionFactory()Constructs a newLettuceConnectionFactory
instance with default settings. -
LettuceConnectionFactory
Constructs a newLettuceConnectionFactory
instance with default settings. -
LettuceConnectionFactory
Constructs a newLettuceConnectionFactory
instance using the givenRedisSocketConfiguration
.- Parameters:
redisConfiguration
- must not be null.- Since:
- 2.1
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisConfiguration redisConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisStaticMasterReplicaConfiguration
andLettuceClientConfiguration
.- Parameters:
redisConfiguration
- must not be null.clientConfiguration
- must not be null.- Since:
- 2.1
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactory
instance using the givenRedisClusterConfiguration
applied to create aRedisClusterClient
.- Parameters:
clusterConfiguration
- must not be null.- Since:
- 1.7
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisClusterConfiguration
andLettuceClientConfiguration
.- Parameters:
clusterConfiguration
- must not be null.clientConfiguration
- must not be null.- Since:
- 2.0
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactory
instance using the givenRedisSentinelConfiguration
.- Parameters:
sentinelConfiguration
- must not be null.- Since:
- 1.6
-
LettuceConnectionFactory
public LettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisSentinelConfiguration
andLettuceClientConfiguration
.- Parameters:
sentinelConfiguration
- must not be null.clientConfiguration
- must not be null.- Since:
- 2.0
-
LettuceConnectionFactory
Constructs a newLettuceConnectionFactory
instance with default settings. -
LettuceConnectionFactory
public LettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfiguration, LettuceClientConfiguration clientConfiguration) Constructs a newLettuceConnectionFactory
instance using the givenRedisStandaloneConfiguration
andLettuceClientConfiguration
.- Parameters:
standaloneConfiguration
- must not be null.clientConfiguration
- must not be null.- Since:
- 2.0
-
-
Method Details
-
createRedisConfiguration
Creates aRedisConfiguration
based on aURI
according to the following:- If
redisUri
contains sentinels, aRedisSentinelConfiguration
is returned - If
redisUri
has a configured socket aRedisSocketConfiguration
is returned - Otherwise a
RedisStandaloneConfiguration
is returned
- Parameters:
redisUri
- the connection URI in the format of aRedisURI
.- Returns:
- an appropriate
RedisConfiguration
instance representing the Redis URI. - Since:
- 2.5.3
- See Also:
-
createRedisConfiguration(RedisURI)
RedisURI
- If
-
createRedisConfiguration
Creates aRedisConfiguration
based on aRedisURI
according to the following:- If
RedisURI
contains sentinels, aRedisSentinelConfiguration
is returned - If
RedisURI
has a configured socket aRedisSocketConfiguration
is returned - Otherwise a
RedisStandaloneConfiguration
is returned
- Parameters:
redisUri
- the connection URI.- Returns:
- an appropriate
RedisConfiguration
instance representing the Redis URI. - Since:
- 2.5.3
- See Also:
-
RedisURI
- If
-
setExecutor
Configures theexecutor
used to execute commands asynchronously across the cluster.- Parameters:
executor
-executor
used 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
- ifLettuceClientConfiguration
is 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
- ifLettuceClientConfiguration
is immutable.
-
isVerifyPeer
public boolean isVerifyPeer()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
- ifLettuceClientConfiguration
is 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
- ifLettuceClientConfiguration
is 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
LettuceConnection
if 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 connections
should be eagerly initialized. Eager initialization requires a running Redis instance during application startup to allow early validation of connection factory configuration. Eager initialization also prevents blocking connect while using reactive API and is recommended for reactive API usage.- Returns:
- {@link true} if the shared connection is initialized upon
afterPropertiesSet()
. - Since:
- 2.2
-
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
- ifLettuceClientConfiguration
is immutable.- Since:
- 2.1
-
getNativeClient
Returns the nativeAbstractRedisClient
used by this instance. The client is initialized as part ofthe bean initialization lifecycle
and only available when this connection factory is initialized.Depending on the configuration, the client can be either
RedisClient
orRedisClusterClient
.- Returns:
- the native
AbstractRedisClient
. Can be null if not initialized. - Since:
- 2.5
- See Also:
-
getRequiredNativeClient
public io.lettuce.core.AbstractRedisClient getRequiredNativeClient()Returns the nativeAbstractRedisClient
used by this instance. The client is initialized as part ofthe bean initialization lifecycle
and only available when this connection factory is initialized. ThrowsIllegalStateException
if not yet initialized.Depending on the configuration, the client can be either
RedisClient
orRedisClusterClient
.- 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
,RedisSentinelConfiguration
orRedisClusterConfiguration
.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
- ifLettuceClientConfiguration
is immutable.- Since:
- 1.6
-
getClientResources
Get theClientResources
to 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, configureClientResources
usingLettuceClientConfiguration
.Sets theClientResources
to reuse the client infrastructure.
Set to null to not share resources.- Parameters:
clientResources
- can be null.- Throws:
IllegalStateException
- ifLettuceClientConfiguration
is immutable.- Since:
- 1.7
-
getClientConfiguration
- Returns:
- the
LettuceClientConfiguration
. - Since:
- 2.0
-
getStandaloneConfiguration
- Returns:
- the
RedisStandaloneConfiguration
. - Since:
- 2.0
-
getSocketConfiguration
- Returns:
- the
RedisSocketConfiguration
or 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
-
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:
getConvertPipelineAndTxResults
in interfaceRedisConnectionFactory
- Returns:
true
to convert pipeline and transaction results;false
otherwise.
-
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
-true
to convert pipeline and transaction results;false
otherwise.
-
isRedisSentinelAware
public boolean isRedisSentinelAware()- Returns:
- true when
RedisSentinelConfiguration
is present. - Since:
- 1.5
-
isClusterAware
public boolean isClusterAware()- Returns:
- true when
RedisClusterConfiguration
is present. - Since:
- 1.7
-
start
public void start() -
stop
public void stop() -
getPhase
public int getPhase()- Specified by:
getPhase
in interfacePhased
- Specified by:
getPhase
in 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:
-
isRunning
public boolean isRunning() -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
-
getConnection
Description copied from interface:RedisConnectionFactory
Returns a suitableconnection
for interacting with Redis.- Specified by:
getConnection
in interfaceRedisConnectionFactory
- Returns:
connection
for interacting with Redis.
-
getClusterConnection
Description copied from interface:RedisConnectionFactory
Returns a suitableconnection
for interacting with Redis Cluster.- Specified by:
getClusterConnection
in interfaceRedisConnectionFactory
- Returns:
- a
connection
for interacting with Redis Cluster.
-
getSentinelConnection
Description copied from interface:RedisConnectionFactory
Returns a suitableconnection
for interacting with Redis Sentinel.- Specified by:
getSentinelConnection
in interfaceRedisConnectionFactory
- Returns:
- a
connection
for 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 forLettuceConnection
creation.- Parameters:
sharedConnection
- the sharedStatefulRedisConnection
ifgetShareNativeConnection()
is true; null otherwise.connectionProvider
- theLettuceConnectionProvider
to 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 forLettuceClusterConnection
creation.- Parameters:
sharedConnection
- the sharedStatefulRedisConnection
ifgetShareNativeConnection()
is true; null otherwise.connectionProvider
- theLettuceConnectionProvider
to release connections.topologyProvider
- theClusterTopologyProvider
.clusterCommandExecutor
- theClusterCommandExecutor
to 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:
getReactiveConnection
in interfaceReactiveRedisConnectionFactory
- Returns:
- a reactive Redis connection.
-
getReactiveClusterConnection
public org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisClusterConnection getReactiveClusterConnection()- Specified by:
getReactiveClusterConnection
in interfaceReactiveRedisConnectionFactory
- Returns:
- a reactive Redis Cluster connection.
-
initConnection
public void initConnection()Initialize the shared connection ifnative connection sharing
is 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:
translateExceptionIfPossible
in interfacePersistenceExceptionTranslator
-
doCreateConnectionProvider
protected LettuceConnectionProvider doCreateConnectionProvider(io.lettuce.core.AbstractRedisClient client, io.lettuce.core.codec.RedisCodec<?, ?> codec) Create aLettuceConnectionProvider
givenAbstractRedisClient
andRedisCodec
. Configuration of this connection factory specifies the type of the created connection provider. This method creates either aLettuceConnectionProvider
for eitherRedisClient
orRedisClusterClient
. Subclasses may override this method to decorate the connection provider.- Parameters:
client
- eitherRedisClient
orRedisClusterClient
, must not be null.codec
- used for connection creation, must not be null. By default, abyte[]
codec. Reactive connections require aByteBuffer
codec.- Returns:
- the connection provider.
- Since:
- 2.1
-
createClient
protected io.lettuce.core.AbstractRedisClient createClient()
-
LettuceClientConfiguration
.