|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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.
Constructor Summary | |
---|---|
LettuceConnectionFactory()
Constructs a new LettuceConnectionFactory instance with
default settings. |
|
LettuceConnectionFactory(String host,
int port)
Constructs a new LettuceConnectionFactory instance with
default settings. |
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
destroy()
|
RedisConnection |
getConnection()
Provides a suitable connection for interacting with Redis. |
int |
getDatabase()
Returns the index of the database. |
String |
getHostName()
Returns the current host. |
protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> |
getNativeConnection()
|
int |
getPort()
Returns the current port. |
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 |
setDatabase(int index)
Sets the index of the database used by this connection factory. |
void |
setHostName(String host)
Sets the host. |
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.
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 indexprotected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> getNativeConnection()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |