DATAREDIS-1106 - Remove expiration phantom key on delete via KeyValueAdapter.
Original pull request: #521.
This commit is contained in:
committed by
Mark Paluch
parent
86b3f45783
commit
cca1f7a8cf
@@ -329,8 +329,14 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
|
||||
connection.del(keyToDelete);
|
||||
connection.sRem(binKeyspace, binId);
|
||||
|
||||
new IndexWriter(connection, converter).removeKeyFromIndexes(asString(keyspace), binId);
|
||||
|
||||
RedisPersistentEntity<?> persistentEntity = converter.getMappingContext().getPersistentEntity(type);
|
||||
if (persistentEntity != null && persistentEntity.isExpiring()) {
|
||||
|
||||
byte[] phantomKey = ByteUtils.concat(keyToDelete, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX);
|
||||
connection.del(phantomKey);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,4 +31,11 @@ public interface TimeToLiveAccessor {
|
||||
*/
|
||||
@Nullable
|
||||
Long getTimeToLive(Object source);
|
||||
|
||||
/**
|
||||
* @param type must not be {@literal null}.
|
||||
* @return return {@literal true} if the entity could potentially expire.
|
||||
* @since ? (depends on backport)
|
||||
*/
|
||||
boolean isExpiringEntity(Class<?> type);
|
||||
}
|
||||
|
||||
@@ -206,10 +206,6 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
|
||||
this.mappingContext = mappingContext;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.TimeToLiveResolver#resolveTimeToLive(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public Long getTimeToLive(final Object source) {
|
||||
@@ -283,6 +279,24 @@ public class RedisMappingContext extends KeyValueMappingContext<RedisPersistentE
|
||||
return defaultTimeout;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.TimeToLiveResolver#isExpiringEntity(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public boolean isExpiringEntity(Class<?> type) {
|
||||
|
||||
Long defaultTimeOut = resolveDefaultTimeOut(type);
|
||||
|
||||
if (defaultTimeOut != null && defaultTimeOut > 0) {
|
||||
return true;
|
||||
}
|
||||
if (resolveTtlProperty(type) != null) {
|
||||
return true;
|
||||
}
|
||||
return resolveTimeMethod(type) != null;
|
||||
}
|
||||
|
||||
private Long resolveDefaultTimeOut(Class<?> type) {
|
||||
|
||||
if (this.defaultTimeouts.containsKey(type)) {
|
||||
|
||||
@@ -52,4 +52,11 @@ public interface RedisPersistentEntity<T> extends KeyValuePersistentEntity<T, Re
|
||||
@Nullable
|
||||
RedisPersistentProperty getExplicitTimeToLiveProperty();
|
||||
|
||||
/**
|
||||
* @return {@literal true} if the entity could potentially expire.
|
||||
* @since ? (depends on backport)
|
||||
*/
|
||||
default boolean isExpiring() {
|
||||
return getTimeToLiveAccessor().isExpiringEntity(getType());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user