Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.data.redis.connection.lettuce
Class LettuceConnectionFactory

    java.lang.Object
      org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory

All Implemented Interfaces:
  DisposableBean, InitializingBean, PersistenceExceptionTranslator, RedisConnectionFactory

    public class LettuceConnectionFactory

extends Object
implements InitializingBean, DisposableBean, RedisConnectionFactory

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

### LettuceConnectionFactory

    public LettuceConnectionFactory()

  Constructs a new `LettuceConnectionFactory` instance with default settings.

### LettuceConnectionFactory

    public LettuceConnectionFactory(String host,
                                    int port)

  Constructs a new `LettuceConnectionFactory` instance with default settings.

### LettuceConnectionFactory

    public LettuceConnectionFactory(LettucePool pool)

Method Detail

### afterPropertiesSet

    public void afterPropertiesSet()

  Specified by:
    `afterPropertiesSet` in interface `InitializingBean`

### destroy

    public void destroy()

  Specified by:
    `destroy` in interface `DisposableBean`

### getConnection

    public RedisConnection getConnection()

  Description copied from interface: `RedisConnectionFactory`
  Provides a suitable connection for interacting with Redis.

  Specified by:
    `getConnection` in interface `RedisConnectionFactory`
  Returns:
    connection for interacting with Redis.

### initConnection

    public void initConnection()

### resetConnection

    public void resetConnection()

  Reset the underlying shared Connection, to be reinitialized on next access.

### validateConnection

    public void validateConnection()

  Validate the shared Connection and reinitialize if invalid

### translateExceptionIfPossible

    public DataAccessException translateExceptionIfPossible(RuntimeException ex)

  Specified by:
    `translateExceptionIfPossible` in interface `PersistenceExceptionTranslator`

### getHostName

    public String getHostName()

  Returns the current host.

  Returns:
    the host

### setHostName

    public void setHostName(String host)

  Sets the host.

  Parameters:
    `host` - the host to set

### getPort

    public int getPort()

  Returns the current port.

  Returns:
    the port

### setPort

    public void setPort(int port)

  Sets the port.

  Parameters:
    `port` - the port to set

### getTimeout

    public long getTimeout()

  Returns the connection timeout (in milliseconds).

  Returns:
    connection timeout

### setTimeout

    public void setTimeout(long timeout)

  Sets the connection timeout (in milliseconds).

  Parameters:
    `timeout` - connection timeout

### 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 to `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.

  Parameters:
    `validateConnection` - enable connection validation

### getShareNativeConnection

    public boolean getShareNativeConnection()

  Indicates if multiple `LettuceConnection`s should share a single native connection.

  Returns:
    native connection shared

### setShareNativeConnection

    public void setShareNativeConnection(boolean shareNativeConnection)

  Enables multiple `LettuceConnection`s to share a single native connection. If set to false, every operation on `LettuceConnection` will open and close a socket.

  Parameters:
    `shareNativeConnection` - enable connection sharing

### getDatabase

    public int getDatabase()

  Returns the index of the database.

  Returns:
    Returns the database index

### setDatabase

    public void setDatabase(int index)

  Sets the index of the database used by this connection factory. Default is 0.

  Parameters:
    `index` - database index

### getPassword

    public String getPassword()

  Returns the password used for authenticating with the Redis server.

  Returns:
    password for authentication

### setPassword

    public void setPassword(String password)

  Sets the password used for authenticating with the Redis server.

  Parameters:
    `password` - the password to set

### getConvertPipelineAndTxResults

    public boolean getConvertPipelineAndTxResults()

  Specifies if pipelined results should be converted to the expected data type. If false, results of `LettuceConnection.closePipeline()` and {LettuceConnection#exec()} will be of the type returned by the Lettuce driver

  Specified by:
    `getConvertPipelineAndTxResults` in interface `RedisConnectionFactory`
  Returns:
    Whether or not to convert pipeline and tx results

### setConvertPipelineAndTxResults

    public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults)

  Specifies if pipelined and transaction results should be converted to the expected data type. If false, results of `LettuceConnection.closePipeline()` and {LettuceConnection#exec()} will be of the type returned by the Lettuce driver

  Parameters:
    `convertPipelineAndTxResults` - Whether or not to convert pipeline and tx results

### getSharedConnection

    protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> getSharedConnection()

### createLettuceConnector

    protected com.lambdaworks.redis.RedisAsyncConnection<byte[],byte[]> createLettuceConnector()

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD