redis20 - SpringBoot 与 redis 客户端 lettuce集成应用

需知  

  目前 java 操作 redis 的客户端有jedis Lettuce

  在 springboot1.x 系列中,使用的是 jedis

  到了 springboot2.x 系列使用的是 Lettuce

  目前我们线上开发基本上都使用的版本是 springboot2.x 系列,所以我们需要会使用 Lettuce

  关于 jedis lettuce 的区别在 redis19 章节已经聊过了,这里就不做冗余阐述了。

实现步骤

 1、添加 pom 依赖

<!--springboot中的redis依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- lettuce pool 缓存连接池-->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>

  注意点:使用pool,那么必须在 pom.xml 添加上 commons-pool2 的依赖。没配置 pool 的话,可以不引用。

 2、配置 redis.properties,其中如下:

spring.redis.host=127.0.0.1
spring.redis.port=6379
#连接池最大链接数默认值为8
spring.redis.lettuce.pool.max-active=8
#连接池最大阻塞时间(使用负值表示没有限制)默认为-1
spring.redis.lettuce.pool.max-wait=-1
#连接池中的最大空闲连接数 默认为8
spring.redis.lettuce.pool.max-idle=8
#连接池中的最小空闲连接数 默认为8
spring.redis.lettuce.pool.min-idle=0

 

posted @ 2020-08-15 00:09  星火燎原智勇  阅读(292)  评论(0编辑  收藏  举报