|
@@ -15,11 +15,12 @@ import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
|
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
|
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
-import redis.clients.jedis.JedisPoolConfig;
|
|
|
+//import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
|
|
@Configuration
|
|
|
@EnableCaching
|
|
@@ -54,7 +55,7 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
private int minIdle;
|
|
|
|
|
|
@Autowired
|
|
|
- private JedisConnectionFactory jedisConnectionFactory;
|
|
|
+ private LettuceConnectionFactory lettuceConnectionFactory;
|
|
|
|
|
|
@Bean
|
|
|
public JedisPoolConfig getRedisConfig() {
|
|
@@ -67,9 +68,9 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
}
|
|
|
|
|
|
@Bean(destroyMethod = "destroy")
|
|
|
- public JedisConnectionFactory redisConnectionFactory() {
|
|
|
+ public LettuceConnectionFactory redisConnectionFactory() {
|
|
|
log.info("Create JedisConnectionFactory successful");
|
|
|
- JedisConnectionFactory factory = new JedisConnectionFactory();
|
|
|
+ LettuceConnectionFactory factory = new LettuceConnectionFactory();
|
|
|
factory.setHostName(host);
|
|
|
factory.setPort(port);
|
|
|
factory.setTimeout(timeout);
|
|
@@ -86,7 +87,7 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
// 初始化缓存管理器,在这里我们可以缓存的整体过期时间什么的,我这里默认没有配置
|
|
|
RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager
|
|
|
.RedisCacheManagerBuilder
|
|
|
- .fromConnectionFactory(jedisConnectionFactory);
|
|
|
+ .fromConnectionFactory(lettuceConnectionFactory);
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
@@ -96,9 +97,9 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
}
|
|
|
|
|
|
@Bean
|
|
|
- public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory jedisConnectionFactory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
|
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
|
|
|
- redisTemplate.setConnectionFactory(jedisConnectionFactory);
|
|
|
+ redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
|
|
|
|
|
// value值的序列化
|
|
|
redisTemplate.setValueSerializer(getSerializer());
|
|
@@ -147,7 +148,7 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean(name = "redisTemplateForIdc")
|
|
|
- public RedisTemplate<String, Object> redisTemplateForIdc(JedisConnectionFactory factory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplateForIdc(LettuceConnectionFactory factory) {
|
|
|
return getRedisTemplate(factory, Integer.valueOf(databaseIdc));
|
|
|
}
|
|
|
|
|
@@ -158,7 +159,7 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean(name = "redisTemplateForSms")
|
|
|
- public RedisTemplate<String, Object> redisTemplateForSms(JedisConnectionFactory factory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplateForSms(LettuceConnectionFactory factory) {
|
|
|
return getRedisTemplate(factory, Integer.valueOf(databaseSms));
|
|
|
}
|
|
|
|
|
@@ -169,7 +170,7 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean(name = "redisTemplateForImg")
|
|
|
- public RedisTemplate<String, Object> redisTemplateForImg(JedisConnectionFactory factory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplateForImg(LettuceConnectionFactory factory) {
|
|
|
return getRedisTemplate(factory, Integer.valueOf(databaseImg));
|
|
|
}
|
|
|
|
|
@@ -180,12 +181,12 @@ public class RedisConfigurer extends CachingConfigurerSupport {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean(name = "redisTemplateForToken")
|
|
|
- public RedisTemplate<String, Object> redisTemplateForToken(JedisConnectionFactory factory) {
|
|
|
+ public RedisTemplate<String, Object> redisTemplateForToken(LettuceConnectionFactory factory) {
|
|
|
return getRedisTemplate(factory, Integer.valueOf(databaseToken));
|
|
|
}
|
|
|
|
|
|
- private RedisTemplate<String, Object> getRedisTemplate(JedisConnectionFactory factory, Integer database) {
|
|
|
- JedisConnectionFactory factory2 = new JedisConnectionFactory();
|
|
|
+ private RedisTemplate<String, Object> getRedisTemplate(LettuceConnectionFactory factory, Integer database) {
|
|
|
+ LettuceConnectionFactory factory2 = new LettuceConnectionFactory();
|
|
|
BeanUtil.copyProperties(factory, factory2);
|
|
|
factory2.setDatabase(database);
|
|
|
|