SpringBoot集成Lettuce 连接超时时间 spring.redis.timeout1000 连接池最大连接数(使用负值表示没有限制) spring.redis.lettuce.pool.maxactive50 连接池中的最小空闲连接 spring.redis.lettuce.pool.minidle5 连接池中的最大空闲连接 spring.redis.lettuce.pool.maxidle50 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.lettuce.pool.maxwait5000 eviction线程调度时间间隔 spring.redis.pool.timebetweenevictionrunsmillis2000 g. Redis连接配置类RedisConfiguration。 @Bean public RedisTemplate redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) { lettuceConnectionFactory.setShareNativeConnection(false); RedisTemplate template new RedisTemplate<>(); template.setConnectionFactory(lettuceConnectionFactory); //使用Jackson2JsonRedisSerializer替换默认的JdkSerializationRedisSerializer来序列化和反序列化redis的value值 Jackson2JsonRedisSerializer jackson2JsonRedisSerializer new Jackson2JsonRedisSerializer<>(Object.class); ObjectMapper mapper new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NONFINAL, JsonTypeInfo.As.PROPERTY); jackson2JsonRedisSerializer.setObjectMapper(mapper); StringRedisSerializer stringRedisSerializer new StringRedisSerializer(); //key采用String的序列化方式 template.setKeySerializer(stringRedisSerializer); // hash的key也采用String的序列化方式 template.setHashKeySerializer(stringRedisSerializer); // value序列化方式采用jackson template.setValueSerializer(jackson2JsonRedisSerializer); // hash的value序列化方式采用jackson template.setHashValueSerializer(jackson2JsonRedisSerializer); template.afterPropertiesSet(); return template; } SpringBoot+Lettuce单连接方式连接Redis Cluster集群代码示例。 h. 在application.properties配置文件中加上redis相关配置。 spring.redis.cluster.nodeshost:port spring.redis.cluster.maxredirects3 spring.redis.password pwd