|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
public class LettuceConnectionFactory
Connection factory creating Lettuce-based connections.
This factory creates a new LettuceConnection
on each call to getConnection()
. Multiple
LettuceConnection
s share a single thread-safe native connection by default.
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. Inject
a Pool
to pool dedicated connections. If shareNativeConnection is true, the pool 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, the selected connection will be used for all operations.
Constructor Summary | |
---|---|
LettuceConnectionFactory()
Constructs a new LettuceConnectionFactory instance with default settings. |
|
LettuceConnectionFactory(LettucePool pool)
|
|
LettuceConnectionFactory(String host,
int port)
Constructs a new LettuceConnectionFactory instance with default settings. |
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> |
createLettuceConnector()
|
void |
destroy()
|
RedisConnection |
getConnection()
Provides a suitable connection for interacting with Redis. |
boolean |
getConvertPipelineAndTxResults()
Specifies if pipelined results should be converted to the expected data type. |
int |
getDatabase()
Returns the index of the database. |
String |
getHostName()
Returns the current host. |
String |
getPassword()
Returns the password used for authenticating with the Redis server. |
int |
getPort()
Returns the current port. |
protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> |
getSharedConnection()
|
boolean |
getShareNativeConnection()
Indicates if multiple LettuceConnection s should share a single native connection. |
long |
getTimeout()
Returns the connection timeout (in milliseconds). |
boolean |
getValidateConnection()
Indicates if validation of the native Lettuce connection is enabled |
void |
initConnection()
|
void |
resetConnection()
Reset the underlying shared Connection, to be reinitialized on next access. |
void |
setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults)
Specifies if pipelined and transaction results should be converted to the expected data type. |
void |
setDatabase(int index)
Sets the index of the database used by this connection factory. |
void |
setHostName(String host)
Sets the host. |
void |
setPassword(String password)
Sets the password used for authenticating with the Redis server. |
void |
setPort(int port)
Sets the port. |
void |
setShareNativeConnection(boolean shareNativeConnection)
Enables multiple LettuceConnection s to share a single native connection. |
void |
setTimeout(long timeout)
Sets the connection timeout (in milliseconds). |
void |
setValidateConnection(boolean validateConnection)
Enables validation of the shared native Lettuce connection on calls to getConnection() . |
DataAccessException |
translateExceptionIfPossible(RuntimeException ex)
|
void |
validateConnection()
Validate the shared Connection and reinitialize if invalid |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LettuceConnectionFactory()
LettuceConnectionFactory
instance with default settings.
public LettuceConnectionFactory(String host, int port)
LettuceConnectionFactory
instance with default settings.
public LettuceConnectionFactory(LettucePool pool)
Method Detail |
---|
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public void destroy()
destroy
in interface DisposableBean
public RedisConnection getConnection()
RedisConnectionFactory
getConnection
in interface RedisConnectionFactory
public void initConnection()
public void resetConnection()
public void validateConnection()
public DataAccessException translateExceptionIfPossible(RuntimeException ex)
translateExceptionIfPossible
in interface PersistenceExceptionTranslator
public String getHostName()
public void setHostName(String host)
host
- the host to setpublic int getPort()
public void setPort(int port)
port
- the port to setpublic long getTimeout()
public void setTimeout(long timeout)
timeout
- connection timeoutpublic boolean getValidateConnection()
public void setValidateConnection(boolean validateConnection)
getConnection()
. 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.
validateConnection
- enable connection validationpublic boolean getShareNativeConnection()
LettuceConnection
s should share a single native connection.
public void setShareNativeConnection(boolean shareNativeConnection)
LettuceConnection
s to share a single native connection. If set to false, every operation
on LettuceConnection
will open and close a socket.
shareNativeConnection
- enable connection sharingpublic int getDatabase()
public void setDatabase(int index)
index
- database indexpublic String getPassword()
public void setPassword(String password)
password
- the password to setpublic boolean getConvertPipelineAndTxResults()
LettuceConnection.closePipeline()
and {LettuceConnection#exec()} will be of the type returned by the
Lettuce driver
getConvertPipelineAndTxResults
in interface RedisConnectionFactory
public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults)
LettuceConnection.closePipeline()
and {LettuceConnection#exec()} will be of the type returned by the
Lettuce driver
convertPipelineAndTxResults
- Whether or not to convert pipeline and tx resultsprotected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> getSharedConnection()
protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> createLettuceConnector()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |