org.springframework.data.redis.core
Class RedisConnectionUtils

java.lang.Object
  extended by org.springframework.data.redis.core.RedisConnectionUtils

public abstract class RedisConnectionUtils
extends Object

Helper class featuring RedisConnection handling, allowing for reuse of instances within 'transactions'/scopes.


Constructor Summary
RedisConnectionUtils()
           
 
Method Summary
static RedisConnection bindConnection(RedisConnectionFactory factory)
          Binds a new Redis connection (from the given factory) to the current thread, if none is already bound.
static RedisConnection doGetConnection(RedisConnectionFactory factory, boolean allowCreate, boolean bind)
          Gets a Redis connection.
static RedisConnection getConnection(RedisConnectionFactory factory)
          Gets a Redis connection from the given factory.
static boolean isConnectionTransactional(RedisConnection conn, RedisConnectionFactory connFactory)
          Return whether the given Redis connection is transactional, that is, bound to the current thread by Spring's transaction facilities.
static void releaseConnection(RedisConnection conn, RedisConnectionFactory factory)
          Closes the given connection, created via the given factory if not managed externally (i.e. not bound to the thread).
static void unbindConnection(RedisConnectionFactory factory)
          Unbinds and closes the connection (if any) associated with the given factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedisConnectionUtils

public RedisConnectionUtils()
Method Detail

bindConnection

public static RedisConnection bindConnection(RedisConnectionFactory factory)
Binds a new Redis connection (from the given factory) to the current thread, if none is already bound.

Parameters:
factory - connection factory
Returns:
a new Redis connection

getConnection

public static RedisConnection getConnection(RedisConnectionFactory factory)
Gets a Redis connection from the given factory. Is aware of and will return any existing corresponding connections bound to the current thread, for example when using a transaction manager. Will always create a new connection otherwise.

Parameters:
factory - connection factory for creating the connection
Returns:
an active Redis connection

doGetConnection

public static RedisConnection doGetConnection(RedisConnectionFactory factory,
                                              boolean allowCreate,
                                              boolean bind)
Gets a Redis connection. Is aware of and will return any existing corresponding connections bound to the current thread, for example when using a transaction manager. Will create a new Connection otherwise, if allowCreate is true.

Parameters:
factory - connection factory for creating the connection
allowCreate - whether a new (unbound) connection should be created when no connection can be found for the current thread
bind - binds the connection to the thread, in case one was created
Returns:
an active Redis connection

releaseConnection

public static void releaseConnection(RedisConnection conn,
                                     RedisConnectionFactory factory)
Closes the given connection, created via the given factory if not managed externally (i.e. not bound to the thread).

Parameters:
conn - the Redis connection to close
factory - the Redis factory that the connection was created with

unbindConnection

public static void unbindConnection(RedisConnectionFactory factory)
Unbinds and closes the connection (if any) associated with the given factory.

Parameters:
factory - Redis factory

isConnectionTransactional

public static boolean isConnectionTransactional(RedisConnection conn,
                                                RedisConnectionFactory connFactory)
Return whether the given Redis connection is transactional, that is, bound to the current thread by Spring's transaction facilities.

Parameters:
conn - Redis connection to check
connFactory - Redis connection factory that the connection was created with
Returns:
whether the connection is transactional or not