Skip to content

Commit

Permalink
Switch to lettuce Redis driver
Browse files Browse the repository at this point in the history
See gh-124.
  • Loading branch information
mp911de committed Oct 5, 2016
1 parent 36db30c commit 8a725de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jar {
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-data-redis') {
exclude module: 'jedis'
}
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-actuator')
Expand All @@ -57,6 +59,7 @@ dependencies {
compile('org.projectlombok:lombok:1.16.8')
compile('org.flywaydb:flyway-core:4.0')
compile('mysql:mysql-connector-java:5.1.38')
compile('biz.paluch.redis:lettuce:3.5.0.Final')
testCompile('org.springframework.boot:spring-boot-configuration-processor')
testCompile('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.security:spring-security-test')
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/io/pivotal/cla/config/SessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,48 @@

package io.pivotal.cla.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.Cloud;
import org.springframework.cloud.CloudFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

/**
* @author Mark Paluch
*/
@Configuration
@EnableConfigurationProperties(RedisProperties.class)
public class SessionConfig {

@Profile(GitHubClaProfiles.CLOUDFOUNDRY)
@Bean
public RedisConnectionFactory redisConnectionFactory() {
public RedisConnectionFactory cloudRedisConnectionFactory() {
CloudFactory cloudFactory = new CloudFactory();
Cloud cloud = cloudFactory.getCloud();
return cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null);
RedisConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null);

if(connectionFactory instanceof LettuceConnectionFactory){
((LettuceConnectionFactory) connectionFactory).setShutdownTimeout(0);
}

return connectionFactory;
}

@Bean
@ConditionalOnMissingBean(RedisConnectionFactory.class)
public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {

LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setPort(redisProperties.getPort());
connectionFactory.setHostName(redisProperties.getHost());
connectionFactory.setPassword(redisProperties.getPassword());
connectionFactory.setShutdownTimeout(0);

return connectionFactory;
}
}

0 comments on commit 8a725de

Please sign in to comment.