public abstract class RedisConnectionUtils extends Object
RedisConnection from a
RedisConnectionFactory. Includes special support for Spring-managed transactional RedisConnections, e.g.
managed by AbstractPlatformTransactionManager..
Used internally by Spring's RedisTemplate. Can also be used directly in application code.
getConnection(org.springframework.data.redis.connection.RedisConnectionFactory),
releaseConnection(org.springframework.data.redis.connection.RedisConnection, org.springframework.data.redis.connection.RedisConnectionFactory),
TransactionSynchronizationManager| Modifier and Type | Class and Description |
|---|---|
static interface |
RedisConnectionUtils.RedisConnectionProxy
Subinterface of
RedisConnection to be implemented by RedisConnection proxies. |
| Constructor and Description |
|---|
RedisConnectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static RedisConnection |
bindConnection(RedisConnectionFactory factory)
Obtain a
RedisConnection from the given RedisConnectionFactory and binds the connection to the
current thread to be used in closure-scope, if none is already bound. |
static RedisConnection |
bindConnection(RedisConnectionFactory factory,
boolean transactionSupport)
Obtain a
RedisConnection from the given RedisConnectionFactory and binds the connection to the
current thread to be used in closure-scope, if none is already bound. |
static RedisConnection |
doGetConnection(RedisConnectionFactory factory,
boolean allowCreate,
boolean bind,
boolean transactionSupport)
Actually obtain a
RedisConnection from the given RedisConnectionFactory. |
static RedisConnection |
getConnection(RedisConnectionFactory factory)
Obtain a
RedisConnection from the given RedisConnectionFactory. |
static RedisConnection |
getConnection(RedisConnectionFactory factory,
boolean transactionSupport)
Obtain a
RedisConnection from the given RedisConnectionFactory. |
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
RedisConnection, created via the given factory if not managed externally (i.e. not bound
to the transaction). |
static void |
releaseConnection(RedisConnection conn,
RedisConnectionFactory factory,
boolean transactionSupport)
Deprecated.
since 2.4.2, use
releaseConnection(RedisConnection, RedisConnectionFactory) |
static void |
unbindConnection(RedisConnectionFactory factory)
Unbinds and closes the connection (if any) associated with the given factory from closure-scope.
|
public static RedisConnection bindConnection(RedisConnectionFactory factory)
RedisConnection from the given RedisConnectionFactory and binds the connection to the
current thread to be used in closure-scope, if none is already bound. Considers ongoing transactions by reusing the
transaction-bound connection and allows reentrant connection retrieval. Does not bind the connection to potentially
ongoing transactions.factory - connection factorypublic static RedisConnection bindConnection(RedisConnectionFactory factory, boolean transactionSupport)
RedisConnection from the given RedisConnectionFactory and binds the connection to the
current thread to be used in closure-scope, if none is already bound. Considers ongoing transactions by reusing the
transaction-bound connection and allows reentrant connection retrieval. Binds also the connection to the ongoing
transaction if no connection is already bound if transactionSupport is enabled.factory - connection factory.transactionSupport - whether transaction support is enabled.public static RedisConnection getConnection(RedisConnectionFactory factory)
RedisConnection from the given RedisConnectionFactory. Is aware of existing connections
bound to the current transaction (when using a transaction manager) or the current thread (when binding a
connection to a closure-scope). Does not bind newly created connections to ongoing transactions.factory - connection factory for creating the connection.public static RedisConnection getConnection(RedisConnectionFactory factory, boolean transactionSupport)
RedisConnection from the given RedisConnectionFactory. Is aware of existing connections
bound to the current transaction (when using a transaction manager) or the current thread (when binding a
connection to a closure-scope).factory - connection factory for creating the connection.transactionSupport - whether transaction support is enabled.public static RedisConnection doGetConnection(RedisConnectionFactory factory, boolean allowCreate, boolean bind, boolean transactionSupport)
RedisConnection from the given RedisConnectionFactory. Is aware of existing
connections bound to the current transaction (when using a transaction manager) or the current thread (when binding
a connection to a closure-scope). Will create a new RedisConnection otherwise, if allowCreate is
true. This method allows for re-entrance as RedisConnectionHolder keeps track of ref-count.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-transactionSupport - whether transaction support is enabled.public static void releaseConnection(@Nullable RedisConnection conn, RedisConnectionFactory factory)
RedisConnection, created via the given factory if not managed externally (i.e. not bound
to the transaction).conn - the Redis connection to close.factory - the Redis factory that the connection was created with.@Deprecated public static void releaseConnection(@Nullable RedisConnection conn, RedisConnectionFactory factory, boolean transactionSupport)
releaseConnection(RedisConnection, RedisConnectionFactory)RedisConnection, created via the given factory if not managed externally (i.e. not bound
to the transaction).conn - the Redis connection to close.factory - the Redis factory that the connection was created with.transactionSupport - whether transaction support is enabled.public static void unbindConnection(RedisConnectionFactory factory)
factory - Redis factorypublic static boolean isConnectionTransactional(RedisConnection conn, RedisConnectionFactory connFactory)
conn - Redis connection to checkconnFactory - Redis connection factory that the connection was created withCopyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.