-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Institute - Cache institute api data into Redis Cluster instead of st…
…andalone (#336) * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone * GRAD2-2840 - Institute - Cache institute api data into Redis Cluster instead of standalone
- Loading branch information
1 parent
02b8b32
commit 066e125
Showing
22 changed files
with
201 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 31 additions & 31 deletions
62
api/src/main/java/ca/bc/gov/educ/api/trax/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package ca.bc.gov.educ.api.trax.config; | ||
|
||
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; | ||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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.RedisClusterNode; | ||
import org.springframework.data.redis.connection.RedisNode; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.GenericToStringSerializer; | ||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.HostAndPort; | ||
import redis.clients.jedis.JedisCluster; | ||
|
||
import java.time.Duration; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Configuration | ||
@EnableRedisRepositories("ca.bc.gov.educ.api.trax.repository.redis") | ||
public class RedisConfig { | ||
@Autowired | ||
private EducGradTraxApiConstants constants; | ||
|
||
@Bean | ||
public JedisConnectionFactory jedisConnectionFactory() { | ||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); | ||
redisStandaloneConfiguration.setHostName(constants.getRedisUrl()); | ||
redisStandaloneConfiguration.setPort(Integer.parseInt(constants.getRedisPort())); | ||
redisStandaloneConfiguration.setPassword(constants.getRedisSecret()); | ||
|
||
//Cluster Configuration | ||
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(); | ||
RedisNode node0 = new RedisNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort())); | ||
redisClusterConfiguration.addClusterNode(node0); | ||
|
||
RedisClusterNode rcn = new RedisClusterNode(constants.getRedisUrl(), Integer.parseInt(constants.getRedisPort())); | ||
|
||
return new JedisConnectionFactory(redisStandaloneConfiguration); | ||
redisClusterConfiguration.addClusterNode(new RedisClusterNode( | ||
constants.getRedisUrl(), | ||
Integer.parseInt(constants.getRedisPort()))); | ||
redisClusterConfiguration.setPassword(constants.getRedisSecret()); | ||
return new JedisConnectionFactory(redisClusterConfiguration); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate() { | ||
final RedisTemplate<String, Object> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(jedisConnectionFactory()); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setValueSerializer(new GenericToStringSerializer<>(Object.class)); | ||
template.setHashKeySerializer(new JdkSerializationRedisSerializer()); | ||
template.setHashValueSerializer(new JdkSerializationRedisSerializer()); | ||
template.setEnableTransactionSupport(true); | ||
template.afterPropertiesSet(); | ||
|
||
return template; | ||
public JedisCluster jedisCluster() { | ||
Set<HostAndPort> jedisClusterNodes = new HashSet<>(); | ||
jedisClusterNodes.add( | ||
new HostAndPort(constants.getRedisUrl(), | ||
Integer.parseInt(constants.getRedisPort()))); | ||
|
||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); | ||
poolConfig.setMaxTotal(8); | ||
poolConfig.setMaxIdle(8); | ||
poolConfig.setMinIdle(0); | ||
poolConfig.setBlockWhenExhausted(true); | ||
poolConfig.setMaxWait(Duration.ofSeconds(1)); | ||
poolConfig.setTestWhileIdle(true); | ||
poolConfig.setTimeBetweenEvictionRuns(Duration.ofSeconds(1)); | ||
|
||
return new JedisCluster(jedisClusterNodes, 5000, 5000, 3, | ||
constants.getRedisUser(), constants.getRedisSecret(), | ||
"educ-grad-trax-api", poolConfig); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.