Skip to content
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>2.5.0-SNAPSHOT</version>
<version>2.5.0-DATAREDIS-1955-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Andrey Muchnik
* @since 1.7
*/
public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
Expand Down Expand Up @@ -248,6 +249,11 @@ public Object put(Object id, Object item, String keyspace) {
}
}

boolean isNoExpire = rdo.getTimeToLive() == null || rdo.getTimeToLive() != null && rdo.getTimeToLive() < 0;
if (isNoExpire && !isNew && keepShadowCopy()){
connection.del(ByteUtils.concat(objectKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
}

connection.sAdd(toBytes(rdo.getKeyspace()), key);

IndexWriter indexWriter = new IndexWriter(connection, converter);
Expand Down Expand Up @@ -492,7 +498,7 @@ public void update(PartialUpdate<?> update) {
} else {

connection.persist(redisKey);
connection.persist(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
connection.del(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Andrey Muchnik
*/
@ExtendWith(LettuceConnectionFactoryExtension.class)
public class RedisKeyValueAdapterTests {
Expand Down Expand Up @@ -705,6 +706,41 @@ void phantomKeyInsertedOnPutWhenShadowCopyIsInDefaultAndKeyspaceNotificationEnab
assertThat(template.hasKey("persons:1:phantom")).isTrue();
}

@Test // DATAREDIS-1955
void phantomKeyIsDeletedWhenPutWithNegativeTimeToLiveAndOldEntryTimeToLiveWasPositiveAndWhenShadowCopyIsTurnedOn() {
ExpiringPerson rand = new ExpiringPerson();
rand.id = "1";
rand.ttl = 3000L;

adapter.put("1", rand, "persons");

assertThat(template.getExpire("persons:1:phantom")).isPositive();

rand.ttl = -1L;

adapter.put("1", rand, "persons");

assertThat(template.hasKey("persons:1:phantom")).isFalse();
}

@Test // DATAREDIS-1955
void updateWithRefreshTtlAndWithoutPositiveTtlShouldDeletePhantomKey() {
ExpiringPerson person = new ExpiringPerson();
person.id = "1";
person.ttl = 100L;

adapter.put("1", person, "persons");

assertThat(template.getExpire("persons:1:phantom")).isPositive();

PartialUpdate<ExpiringPerson> update = new PartialUpdate<>("1", ExpiringPerson.class) //
.refreshTtl(true);

adapter.update(update);

assertThat(template.hasKey("persons:1:phantom")).isFalse();
}

/**
* Wait up to 5 seconds until {@code key} is no longer available in Redis.
*
Expand Down