DATAREDIS-491 - Polishing.
Set EnableRedisRepositories.enableKeyspaceEvents default to OFF. Expiry notifications require to opt-in. Add JavaDoc. Add documentation for delayed/disabled event listener. Fix spelling. Use property value instead of attribute on RedisKeyValueAdapter bean definition. Remove trailing white spaces. Original pull request: #193.
This commit is contained in:
@@ -98,11 +98,11 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
private RedisOperations<?, ?> redisOps;
|
||||
private RedisConverter converter;
|
||||
private RedisMessageListenerContainer messageListenerContainer;
|
||||
private AtomicReference<KeyExpirationEventMessageListener> expirationListener = new AtomicReference<KeyExpirationEventMessageListener>(
|
||||
private final AtomicReference<KeyExpirationEventMessageListener> expirationListener = new AtomicReference<KeyExpirationEventMessageListener>(
|
||||
null);
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private EnableKeyspaceEvents enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP;
|
||||
private EnableKeyspaceEvents enableKeyspaceEvents = EnableKeyspaceEvents.OFF;
|
||||
|
||||
/**
|
||||
* Creates new {@link RedisKeyValueAdapter} with default {@link RedisMappingContext} and default
|
||||
@@ -144,10 +144,9 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
mappingConverter.setCustomConversions(customConversions == null ? new CustomConversions() : customConversions);
|
||||
mappingConverter.afterPropertiesSet();
|
||||
|
||||
converter = mappingConverter;
|
||||
this.converter = mappingConverter;
|
||||
this.redisOps = redisOps;
|
||||
|
||||
intiMessageListenerContainer();
|
||||
initMessageListenerContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,10 +161,9 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
|
||||
Assert.notNull(redisOps, "RedisOperations must not be null!");
|
||||
|
||||
converter = redisConverter;
|
||||
this.converter = redisConverter;
|
||||
this.redisOps = redisOps;
|
||||
|
||||
intiMessageListenerContainer();
|
||||
initMessageListenerContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +491,9 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
this.expirationListener.get().destroy();
|
||||
}
|
||||
|
||||
this.messageListenerContainer.destroy();
|
||||
if(this.messageListenerContainer != null){
|
||||
this.messageListenerContainer.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -535,12 +535,12 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
|
||||
this.eventPublisher = applicationContext;
|
||||
}
|
||||
|
||||
private void intiMessageListenerContainer() {
|
||||
private void initMessageListenerContainer() {
|
||||
|
||||
this.messageListenerContainer = new RedisMessageListenerContainer();
|
||||
messageListenerContainer.setConnectionFactory(((RedisTemplate<?, ?>) redisOps).getConnectionFactory());
|
||||
messageListenerContainer.afterPropertiesSet();
|
||||
messageListenerContainer.start();
|
||||
this.messageListenerContainer.setConnectionFactory(((RedisTemplate<?, ?>) redisOps).getConnectionFactory());
|
||||
this.messageListenerContainer.afterPropertiesSet();
|
||||
this.messageListenerContainer.start();
|
||||
}
|
||||
|
||||
private void initKeyExpirationListener() {
|
||||
|
||||
@@ -41,8 +41,9 @@ import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||
/**
|
||||
* Annotation to activate Redis repositories. If no base package is configured through either {@link #value()},
|
||||
* {@link #basePackages()} or {@link #basePackageClasses()} it will trigger scanning of the package of annotated class.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 1.7
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@@ -88,14 +89,14 @@ public @interface EnableRedisRepositories {
|
||||
* Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
|
||||
* for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
|
||||
* for {@code PersonRepositoryImpl}.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String repositoryImplementationPostfix() default "Impl";
|
||||
|
||||
/**
|
||||
* Configures the location of where to find the Spring Data named queries properties file.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String namedQueriesLocation() default "";
|
||||
@@ -103,7 +104,7 @@ public @interface EnableRedisRepositories {
|
||||
/**
|
||||
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
|
||||
* {@link Key#CREATE_IF_NOT_FOUND}.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;
|
||||
@@ -111,21 +112,21 @@ public @interface EnableRedisRepositories {
|
||||
/**
|
||||
* Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to
|
||||
* {@link RedisRepositoryFactoryBean}.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?> repositoryFactoryBeanClass() default RedisRepositoryFactoryBean.class;
|
||||
|
||||
/**
|
||||
* Configure the repository base class to be used to create repository proxies for this particular configuration.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?> repositoryBaseClass() default DefaultRepositoryBaseClass.class;
|
||||
|
||||
/**
|
||||
* Configures the name of the {@link KeyValueOperations} bean to be used with the repositories detected.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String keyValueTemplateRef() default "redisKeyValueTemplate";
|
||||
@@ -138,21 +139,21 @@ public @interface EnableRedisRepositories {
|
||||
|
||||
/**
|
||||
* Configures the bean name of the {@link RedisOperations} to be used. Defaulted to {@literal redisTemplate}.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String redisTemplateRef() default "redisTemplate";
|
||||
|
||||
/**
|
||||
* Set up index patterns using simple configuration class.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<? extends IndexConfiguration> indexConfiguration() default IndexConfiguration.class;
|
||||
|
||||
/**
|
||||
* Set up keyspaces for specific types.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<? extends KeyspaceConfiguration> keyspaceConfiguration() default KeyspaceConfiguration.class;
|
||||
@@ -163,6 +164,6 @@ public @interface EnableRedisRepositories {
|
||||
* @return
|
||||
* @since 1.8
|
||||
*/
|
||||
EnableKeyspaceEvents enableKeyspaceEvents() default EnableKeyspaceEvents.ON_DEMAND;
|
||||
EnableKeyspaceEvents enableKeyspaceEvents() default EnableKeyspaceEvents.OFF;
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link RepositoryConfigurationExtension} for Redis.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
@@ -72,7 +72,7 @@ public class RedisRepositoryConfigurationExtension extends KeyValueRepositoryCon
|
||||
return "redis";
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension#getDefaultKeyValueTemplateRef()
|
||||
*/
|
||||
@@ -123,9 +123,12 @@ public class RedisRepositoryConfigurationExtension extends KeyValueRepositoryCon
|
||||
|
||||
redisKeyValueAdapterDefinition.setConstructorArgumentValues(constructorArgumentValuesForRedisKeyValueAdapter);
|
||||
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(configurationSource);
|
||||
AnnotationAttributes aa = (AnnotationAttributes) dfa.getPropertyValue("attributes");
|
||||
redisKeyValueAdapterDefinition.setAttribute("enableKeyspaceEvents", aa.getEnum("enableKeyspaceEvents"));
|
||||
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(configurationSource);
|
||||
AnnotationAttributes attributes = (AnnotationAttributes) fieldAccessor.getPropertyValue("attributes");
|
||||
|
||||
MutablePropertyValues redisKeyValueAdapterProps = new MutablePropertyValues();
|
||||
redisKeyValueAdapterProps.add("enableKeyspaceEvents", attributes.getEnum("enableKeyspaceEvents"));
|
||||
redisKeyValueAdapterDefinition.setPropertyValues(redisKeyValueAdapterProps);
|
||||
|
||||
registerIfNotAlreadyRegistered(redisKeyValueAdapterDefinition, registry, REDIS_ADAPTER_BEAN_NAME,
|
||||
configurationSource);
|
||||
|
||||
Reference in New Issue
Block a user