Skip to content

DATAREDIS-548 - Release connection after command execution in read-only transactions. #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.0.BUILD-SNAPSHOT</version>
<version>1.8.0.DATAREDIS-548-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 the original author or authors.
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@
* @author Costin Leau
* @author Christoph Strobl
* @author Thomas Darimont
* @author Mark Paluch
*/
public abstract class RedisConnectionUtils {

Expand Down Expand Up @@ -199,8 +200,12 @@ public static void releaseConnection(RedisConnection conn, RedisConnectionFactor
return;
}

// Only release non-transactional/non-bound connections.
if (!isConnectionTransactional(conn, factory)) {
// release transactional/read-only and non-transactional/non-bound connections.
// transactional connections for read-only transactions get no synchronizer registered
if (isConnectionTransactional(conn, factory)
&& TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
unbindConnection(factory);
} else if (!isConnectionTransactional(conn, factory)) {
if (log.isDebugEnabled()) {
log.debug("Closing Redis Connection");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
* @author Christoph Strobl
* @author Ninad Divadkar
* @author Anqing Shao
* @author Mark Paluch
* @param <K> the Redis key type against which the template works (usually a String)
* @param <V> the Redis value type against which the template works
* @see StringRedisTemplate
Expand Down Expand Up @@ -212,10 +213,7 @@ public <T> T execute(RedisCallback<T> action, boolean exposeConnection, boolean
// TODO: any other connection processing?
return postProcessResult(result, connToUse, existingConnection);
} finally {

if (!enableTransactionSupport) {
RedisConnectionUtils.releaseConnection(conn, factory);
}
RedisConnectionUtils.releaseConnection(conn, factory);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class with integration tests for transactional use.
*
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@Transactional(transactionManager = "transactionManager")
public abstract class AbstractTransactionalTestBase {
Expand Down Expand Up @@ -129,6 +136,19 @@ public void valueOperationSetShouldBeCommittedCorrectly() {
}
}

/**
* @see DATAREDIS-548
*/
@Test
@Transactional(readOnly = true)
public void valueOperationShouldWorkWithReadOnlyTransactions() {

this.valuesShouldHaveBeenPersisted = false;
for (String key : KEYS) {
template.opsForValue().get(key);
}
}

/**
* @see DATAREDIS-73
*/
Expand All @@ -146,7 +166,7 @@ public void listOperationLPushShoudBeRolledBackCorrectly() {
*/
@Rollback(false)
@Test
public void listOperationLPushShoudBeCommittedCorrectly() {
public void listOperationLPushShouldBeCommittedCorrectly() {

this.valuesShouldHaveBeenPersisted = true;
for (String key : KEYS) {
Expand Down