Skip to content

Commit b82460f

Browse files
christophstroblodrotbohm
authored andcommitted
spring-projects#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.
1 parent b075ca6 commit b82460f

File tree

3 files changed

+3
-115
lines changed

3 files changed

+3
-115
lines changed

redis/cluster/readme.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,14 @@ To run the code in this sample a running cluster environment is required. Please
66

77
## Support for Cluster ##
88

9-
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.
9+
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.
1010

1111
```properties
1212
spring.redis.cluster.nodes[0]=127.0.0.1:30001
1313
spring.redis.cluster.nodes[1]=127.0.0.1:30002
1414
spring.redis.cluster.nodes[2]=127.0.0.1:30003
1515
```
1616

17-
Additionally we need to have the `RedisConnectionFactory` set up with the according `RedisClusterConfiguration`.
18-
19-
```java
20-
@Configuration
21-
@EnableConfigurationProperties(ClusterConfigurationProperties.class)
22-
public class AppConfig {
23-
24-
/**
25-
* Type safe representation of application.properties
26-
*/
27-
@Autowired ClusterConfigurationProperties clusterProperties;
28-
29-
/**
30-
* The connection factory used for obtaining RedisConnection
31-
* uses a RedisClusterConfiguration that points
32-
* to the initial set of nodes.
33-
*/
34-
@Bean
35-
RedisConnectionFactory connectionFactory() {
36-
return new JedisConnectionFactory(
37-
new RedisClusterConfiguration(clusterProperties.getNodes()));
38-
}
39-
40-
/**
41-
* RedisTemplate can be configured with RedisSerializer if needed.
42-
* NOTE: be careful using JSON serializers for key serialization.
43-
*/
44-
@Bean
45-
RedisTemplate<String, String> redisTemplate() {
46-
return new StringRedisTemplate(connectionFactory());
47-
}
48-
}
49-
```
50-
5117
**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.
5218

5319
## Cluster Setup ##

redis/cluster/src/main/java/example/springdata/redis/cluster/AppConfig.java

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,17 @@
1515
*/
1616
package example.springdata.redis.cluster;
1717

18-
import org.springframework.beans.factory.annotation.Autowired;
19-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
20-
import org.springframework.context.annotation.Bean;
21-
import org.springframework.context.annotation.Configuration;
22-
import org.springframework.data.redis.connection.RedisClusterConfiguration;
23-
import org.springframework.data.redis.connection.RedisConnection;
18+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2419
import org.springframework.data.redis.connection.RedisConnectionFactory;
25-
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
2620
import org.springframework.data.redis.core.RedisTemplate;
27-
import org.springframework.data.redis.core.StringRedisTemplate;
28-
import org.springframework.data.redis.serializer.RedisSerializer;
2921

3022
/**
3123
* Application context configuration setting up {@link RedisConnectionFactory} and {@link RedisTemplate} according to
3224
* {@link ClusterConfigurationProperties}.
3325
*
3426
* @author Christoph Strobl
3527
*/
36-
@Configuration
37-
@EnableConfigurationProperties(ClusterConfigurationProperties.class)
28+
@EnableAutoConfiguration
3829
public class AppConfig {
3930

40-
/**
41-
* Type safe representation of application.properties
42-
*/
43-
@Autowired ClusterConfigurationProperties clusterProperties;
44-
45-
/**
46-
* The connection factory used for obtaining {@link RedisConnection} uses a {@link RedisClusterConfiguration} that
47-
* points to the initial set of nodes.
48-
*/
49-
@Bean
50-
RedisConnectionFactory connectionFactory() {
51-
return new JedisConnectionFactory(new RedisClusterConfiguration(clusterProperties.getNodes()));
52-
}
53-
54-
/**
55-
* {@link RedisTemplate} can be configured with {@link RedisSerializer} if needed. <br />
56-
* <b>NOTE:</b> be careful using JSON @link RedisSerializer} for key serialization.
57-
*/
58-
@Bean
59-
RedisTemplate<String, String> redisTemplate() {
60-
return new StringRedisTemplate(connectionFactory());
61-
}
6231
}

redis/cluster/src/main/java/example/springdata/redis/cluster/ClusterConfigurationProperties.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)