1 | package org.cardanofoundation.explorer.api.config.redis.standalone; | |
2 | ||
3 | import java.util.Arrays; | |
4 | ||
5 | import lombok.extern.log4j.Log4j2; | |
6 | import lombok.val; | |
7 | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | |
9 | import org.springframework.beans.factory.annotation.Qualifier; | |
10 | import org.springframework.beans.factory.annotation.Value; | |
11 | import org.springframework.cache.annotation.CachingConfigurer; | |
12 | import org.springframework.cache.interceptor.KeyGenerator; | |
13 | import org.springframework.context.annotation.Bean; | |
14 | import org.springframework.context.annotation.Configuration; | |
15 | import org.springframework.context.annotation.Profile; | |
16 | import org.springframework.data.redis.cache.RedisCacheManager; | |
17 | import org.springframework.data.redis.connection.RedisConnectionFactory; | |
18 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | |
19 | import org.springframework.data.redis.connection.jedis.JedisClientConfiguration; | |
20 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; | |
21 | import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; | |
22 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | |
23 | import org.springframework.data.redis.core.RedisTemplate; | |
24 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | |
25 | import org.springframework.data.redis.serializer.GenericToStringSerializer; | |
26 | import org.springframework.data.redis.serializer.StringRedisSerializer; | |
27 | ||
28 | @Log4j2 | |
29 | @Configuration | |
30 | @Profile("standalone") | |
31 | public class RedisStandaloneConfig implements CachingConfigurer { | |
32 | ||
33 | @Value("${spring.redis.standalone.host}") | |
34 | private String hostname; | |
35 | ||
36 | @Value("${spring.redis.standalone.port}") | |
37 | private Integer port; | |
38 | ||
39 | @Value("${spring.redis.password}") | |
40 | private String password; | |
41 | ||
42 | @Value("${spring.redis.standalone.useSsl}") | |
43 | private boolean useSsl; | |
44 | ||
45 | @Bean | |
46 | RedisStandaloneConfiguration redisStandaloneConfiguration() { | |
47 | RedisStandaloneConfiguration redisStandaloneConfiguration = | |
48 | new RedisStandaloneConfiguration(hostname, port); | |
49 |
1
1. redisStandaloneConfiguration : removed call to org/springframework/data/redis/connection/RedisStandaloneConfiguration::setPassword → NO_COVERAGE |
redisStandaloneConfiguration.setPassword(password); |
50 |
1
1. redisStandaloneConfiguration : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::redisStandaloneConfiguration → NO_COVERAGE |
return redisStandaloneConfiguration; |
51 | } | |
52 | ||
53 | @Bean(name = "lettuceConnectionFactory") | |
54 | @Autowired | |
55 | LettuceConnectionFactory lettuceConnectionFactory( | |
56 | RedisStandaloneConfiguration redisStandaloneConfiguration) { | |
57 |
1
1. lettuceConnectionFactory : negated conditional → NO_COVERAGE |
if (useSsl) { |
58 |
1
1. lettuceConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::lettuceConnectionFactory → NO_COVERAGE |
return new LettuceConnectionFactory( |
59 | redisStandaloneConfiguration, LettuceClientConfiguration.builder().useSsl().build()); | |
60 | } else { | |
61 |
1
1. lettuceConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::lettuceConnectionFactory → NO_COVERAGE |
return new LettuceConnectionFactory(redisStandaloneConfiguration); |
62 | } | |
63 | } | |
64 | ||
65 | @Bean | |
66 | @Autowired | |
67 | RedisTemplate<String, ?> redisTemplate( // NOSONAR | |
68 | final LettuceConnectionFactory lettuceConnectionFactory) { | |
69 | var redisTemplate = new RedisTemplate<String, Object>(); | |
70 |
1
1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE |
redisTemplate.setConnectionFactory(lettuceConnectionFactory); |
71 |
1
1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE |
redisTemplate.setKeySerializer(new StringRedisSerializer()); |
72 |
1
1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE |
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); |
73 |
1
1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE |
redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer()); |
74 |
1
1. redisTemplate : removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE |
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); |
75 |
1
1. redisTemplate : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::redisTemplate → NO_COVERAGE |
return redisTemplate; |
76 | } | |
77 | ||
78 | @Bean | |
79 | @Autowired | |
80 | RedisTemplate<String, String> redisTemplateString( // NOSONAR // TODO will remove in next version | |
81 | final LettuceConnectionFactory lettuceConnectionFactory) { | |
82 | var redisTemplate = new RedisTemplate<String, String>(); | |
83 |
1
1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setConnectionFactory → NO_COVERAGE |
redisTemplate.setConnectionFactory(lettuceConnectionFactory); |
84 |
1
1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setKeySerializer → NO_COVERAGE |
redisTemplate.setKeySerializer(new StringRedisSerializer()); |
85 |
1
1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setValueSerializer → NO_COVERAGE |
redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Object.class)); |
86 |
1
1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setDefaultSerializer → NO_COVERAGE |
redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer()); |
87 |
1
1. redisTemplateString : removed call to org/springframework/data/redis/core/RedisTemplate::setHashValueSerializer → NO_COVERAGE |
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); |
88 |
1
1. redisTemplateString : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::redisTemplateString → NO_COVERAGE |
return redisTemplate; |
89 | } | |
90 | ||
91 | @Override | |
92 | public KeyGenerator keyGenerator() { | |
93 |
1
1. keyGenerator : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::keyGenerator → NO_COVERAGE |
return (target, method, params) -> { |
94 | val sb = new StringBuilder(); | |
95 | sb.append(target.getClass().getName()); | |
96 | sb.append(method.getName()); | |
97 |
1
1. lambda$keyGenerator$0 : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
Arrays.stream(params).sequential().forEach(sb::append); |
98 | log.info("call Redis cache Key : " + sb); | |
99 |
1
1. lambda$keyGenerator$0 : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::lambda$keyGenerator$0 → NO_COVERAGE |
return sb.toString(); |
100 | }; | |
101 | } | |
102 | ||
103 | @Bean(name = "jedisConnectionFactory") | |
104 | @Autowired | |
105 | JedisConnectionFactory jedisConnectionFactory( | |
106 | RedisStandaloneConfiguration redisStandaloneConfiguration) { | |
107 |
1
1. jedisConnectionFactory : negated conditional → NO_COVERAGE |
if (useSsl) { |
108 |
1
1. jedisConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::jedisConnectionFactory → NO_COVERAGE |
return new JedisConnectionFactory( |
109 | redisStandaloneConfiguration, JedisClientConfiguration.builder().useSsl().build()); | |
110 | } else { | |
111 |
1
1. jedisConnectionFactory : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::jedisConnectionFactory → NO_COVERAGE |
return new JedisConnectionFactory(redisStandaloneConfiguration); |
112 | } | |
113 | } | |
114 | ||
115 | @Bean(name = "cacheManager") | |
116 | public RedisCacheManager cacheManager( | |
117 | @Qualifier("jedisConnectionFactory") RedisConnectionFactory connectionFactory) { | |
118 |
1
1. cacheManager : replaced return value with null for org/cardanofoundation/explorer/api/config/redis/standalone/RedisStandaloneConfig::cacheManager → NO_COVERAGE |
return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(connectionFactory) |
119 | .build(); | |
120 | } | |
121 | } | |
Mutations | ||
49 |
1.1 |
|
50 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
61 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
93 |
1.1 |
|
97 |
1.1 |
|
99 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
111 |
1.1 |
|
118 |
1.1 |