#158 - Remove workaround for Redis cluster configuration.

SpringBoot 1.4M1 ships with auto configuration for spring.redis.cluster so we removed the work around using ConfigurationProperties.
This commit is contained in:
Christoph Strobl
2016-04-05 17:39:59 +02:00
committed by Oliver Gierke
parent b075ca6358
commit b82460f33c
3 changed files with 3 additions and 115 deletions

View File

@@ -6,7 +6,7 @@ To run the code in this sample a running cluster environment is required. Please
## Support for Cluster ##
Cluster Support uses the same building blocks as the non clustered counterpart. We use `application.properties` to point to an initial set of known cluster nodes.
Cluster Support uses the same building blocks as the non clustered counterpart. We use `application.properties` to point to an initial set of known cluster nodes which will be picked up by the auto configuration.
```properties
spring.redis.cluster.nodes[0]=127.0.0.1:30001
@@ -14,40 +14,6 @@ spring.redis.cluster.nodes[1]=127.0.0.1:30002
spring.redis.cluster.nodes[2]=127.0.0.1:30003
```
Additionally we need to have the `RedisConnectionFactory` set up with the according `RedisClusterConfiguration`.
```java
@Configuration
@EnableConfigurationProperties(ClusterConfigurationProperties.class)
public class AppConfig {
/**
* Type safe representation of application.properties
*/
@Autowired ClusterConfigurationProperties clusterProperties;
/**
* The connection factory used for obtaining RedisConnection
* uses a RedisClusterConfiguration that points
* to the initial set of nodes.
*/
@Bean
RedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory(
new RedisClusterConfiguration(clusterProperties.getNodes()));
}
/**
* RedisTemplate can be configured with RedisSerializer if needed.
* NOTE: be careful using JSON serializers for key serialization.
*/
@Bean
RedisTemplate<String, String> redisTemplate() {
return new StringRedisTemplate(connectionFactory());
}
}
```
**INFORMATION:** The tests flush the db of all known instances during the JUnit _setup_ phase to allow inspecting data directly on the cluster nodes after a test is run.
## Cluster Setup ##

View File

@@ -15,17 +15,9 @@
*/
package example.springdata.redis.cluster;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
/**
* Application context configuration setting up {@link RedisConnectionFactory} and {@link RedisTemplate} according to
@@ -33,30 +25,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
*
* @author Christoph Strobl
*/
@Configuration
@EnableConfigurationProperties(ClusterConfigurationProperties.class)
@EnableAutoConfiguration
public class AppConfig {
/**
* Type safe representation of application.properties
*/
@Autowired ClusterConfigurationProperties clusterProperties;
/**
* The connection factory used for obtaining {@link RedisConnection} uses a {@link RedisClusterConfiguration} that
* points to the initial set of nodes.
*/
@Bean
RedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory(new RedisClusterConfiguration(clusterProperties.getNodes()));
}
/**
* {@link RedisTemplate} can be configured with {@link RedisSerializer} if needed. <br />
* <b>NOTE:</b> be careful using JSON @link RedisSerializer} for key serialization.
*/
@Bean
RedisTemplate<String, String> redisTemplate() {
return new StringRedisTemplate(connectionFactory());
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2015-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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.redis.cluster;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Type safe representation of {@code spring.redis.cluster.*} properties in {@literal application.properties}.
*
* @author Christoph Strobl
* @author Oliver Gierke
*/
@Component
@ConfigurationProperties(prefix = "spring.redis.cluster")
public class ClusterConfigurationProperties {
private List<String> nodes;
/**
* Get initial collection of known cluster nodes in format {@code host:port}.
*
* @return
*/
public List<String> getNodes() {
return nodes;
}
public void setNodes(List<String> nodes) {
this.nodes = nodes;
}
}