@Override
 public void afterCompletion(int status) {
   // If we haven't closed the Connection in beforeCompletion,
   // close it now. The holder might have been used for other
   // cleanup in the meantime, for example by a Hibernate Session.
   if (this.holderActive) {
     // The thread-bound ConnectionHolder might not be available anymore,
     // since afterCompletion might get called from a different thread.
     TransactionSynchronizationManager.unbindResourceIfPossible(this.dataSource);
     this.holderActive = false;
     if (this.connectionHolder.hasConnection()) {
       releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
       // Reset the ConnectionHolder: It might remain bound to the thread.
       this.connectionHolder.setConnection(null);
     }
   }
   this.connectionHolder.reset();
 }
  /**
   * Unbinds and closes the connection (if any) associated with the given factory.
   *
   * @param factory Redis factory
   */
  public static void unbindConnection(RedisConnectionFactory factory) {

    RedisConnectionHolder connHolder =
        (RedisConnectionHolder) TransactionSynchronizationManager.unbindResourceIfPossible(factory);

    if (connHolder != null) {
      if (connHolder.isTransactionSyncronisationActive()) {
        if (log.isDebugEnabled()) {
          log.debug("Redis Connection will be closed when outer transaction finished.");
        }
      } else {
        if (log.isDebugEnabled()) {
          log.debug("Closing bound connection.");
        }
        RedisConnection connection = connHolder.getConnection();
        connection.close();
      }
    }
  }