spring boot 集成 redis lettuce(jedis)

spring boot framework is already integrated redis, default jedis client to use when 1.xx version, is now used by default lettuce client version 2.xx end

 

The introduction of dependence

 <!-- spring boot redis 缓存引入 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.0.4.RELEASE</version>
        </dependency>

  

 

Profiles

#Redis configuration 
#Redis server address 
spring.redis.host = 127.0.0.1 
#Redis server port 
spring.redis.port = 6379 
#Redis server connection password (blank by default) 
spring.redis.password = 123456 
#Redis database indexes ( the default is 0) 
spring.redis.database = 0 
## connection timeout 
spring.redis.timeout = 60s 

# following connection pool is not recommended for use in SpringBoot2.0 
## connection pool maximum number of connections (use a negative value means no limit) 
# spring.redis.jedis.pool.max-active = 10 
connection pool ## maximum blocking latency (negative values no limit) 
# = -1ms spring.redis.jedis.pool.max the wait- 
## connection pool the maximum connection idle 
# spring.redis.jedis.pool.max. 8-iDLE = 
## minimum connection pool idle connections 
# spring.redis.jedis.pool.min-iDLE = 0 

# Lettuce 
# connection pool maximum number of connections ( using a negative value indicates no limit) 
spring.redis.lettuce.pool.max-Active. 8 =
# Latency connection pool maximum blocking (negative values no limit)
= the wait-10000 spring.redis.lettuce.pool.max 
# connection pool maximum idle connection 
spring.redis.lettuce.pool.max. 8-IDLE = 
# minimum connection pool idle connections 
spring.redis.lettuce.pool. IDLE = 0-min 
# Close timeout 
spring.redis.lettuce.shutdown-timeout = 100

  

 

Configuration config

@Configuration
@AutoConfigureAfter(RedisConfig.class)
public class RedisConfig {

//    @Bean
//    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
//        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
//        redisTemplate.setKeySerializer(new StringRedisSerializer());
//        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
//        redisTemplate.setValueSerializer(new StringRedisSerializer());
//        redisTemplate.setConnectionFactory(factory);
//        return redisTemplate;
//    }

    @Bean
    public RedisTemplate<String, Serializable> redisCacheTemplate(LettuceConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Serializable> template = new RedisTemplate<>();
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        template.setConnectionFactory(redisConnectionFactory);
        return template;
    }
}

  

 

Guess you like

Origin www.cnblogs.com/achengmu/p/11345220.html