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