1
|
package eu.dnetlib.statsapi.repos;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.beans.factory.annotation.Autowired;
|
5
|
import org.springframework.beans.factory.annotation.Value;
|
6
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
7
|
import org.springframework.context.annotation.Bean;
|
8
|
import org.springframework.context.annotation.Configuration;
|
9
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
10
|
import org.springframework.data.redis.core.RedisTemplate;
|
11
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
12
|
import org.springframework.stereotype.Component;
|
13
|
|
14
|
/**
|
15
|
* Created by tsampikos on 20/4/2017.
|
16
|
*/
|
17
|
@Component
|
18
|
@Configuration
|
19
|
@ConfigurationProperties(prefix = "statsapi.redis")
|
20
|
class SpringRedisConfiguration {
|
21
|
|
22
|
private final Logger log = Logger.getLogger(this.getClass());
|
23
|
|
24
|
@Value("${statsapi.redis.hostname}")
|
25
|
String hostname;
|
26
|
|
27
|
@Value("${statsapi.redis.port}")
|
28
|
int port;
|
29
|
|
30
|
@Bean
|
31
|
public JedisConnectionFactory connectionFactory() {
|
32
|
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
33
|
connectionFactory.setHostName(hostname);
|
34
|
connectionFactory.setPort(port);
|
35
|
log.info("Opening redis connection to : " + connectionFactory.getHostName() + ":" + connectionFactory.getPort());
|
36
|
return connectionFactory;
|
37
|
}
|
38
|
|
39
|
@Bean
|
40
|
@Autowired
|
41
|
public RedisTemplate<String, String> redisTemplate() {
|
42
|
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
|
43
|
redisTemplate.setConnectionFactory(connectionFactory());
|
44
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
45
|
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
46
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
47
|
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
48
|
return redisTemplate;
|
49
|
}
|
50
|
}
|