5.7 SpringBoot整合Jedis+Lettuce客户端连接池配置实战

1,478 阅读1分钟

SpringBoot整合Jedis+Lettuce客户端连接池配置实战点击小标题观看视频讲解

简介:SpringBoot整合Jedis+Lettuce客户端连接池配置实战

  • 基于SpringDataRedis可以快速替换底层实现

    • Lettuce连接池介绍(添加连接池)
      <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-pool2</artifactId>
        </dependency>
    
    # 连接池最大连接数(使用负值表示没有限制)
    spring.redis.lettuce.pool.max-active = 10# 连接池中的最大空闲连接
    spring.redis.lettuce.pool.max-idle = 10# 连接池中的最小空闲连接
    spring.redis.lettuce.pool.min-idle = 0# 连接池最大阻塞等待时间(使用负值表示没有限制)
    spring.redis.lettuce.pool.max-wait= -1ms
    ​
    #指定客户端
    spring.redis.client-type = lettuce
    

     

     

    • Jedis连接池介绍(可以不排除lettuce依赖包)
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-redis</artifactId>
          <exclusions>
            <exclusion>
              <groupId>io.lettuce</groupId>
              <artifactId>lettuce-core</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
        
        <!--不用指定版本号,本身spring-data-redis里面有-->
        <dependency>
          <groupId>redis.clients</groupId>
          <artifactId>jedis</artifactId>
        </dependency>
        
    <dependency>
        <groupId>org.apache.commons</groupId>
          <artifactId>commons-pool2</artifactId>
          <version>2.6.1</version>
      </dependency>
    

     

    # 连接池最大连接数(使用负值表示没有限制)
    spring.redis.jedis.pool.max-active = 10# 连接池中的最大空闲连接
    spring.redis.jedis.pool.max-idle = 10# 连接池中的最小空闲连接
    spring.redis.jedis.pool.min-idle = 0# 连接池最大阻塞等待时间(使用负值表示没有限制)
    spring.redis.jedis.pool.max-wait= -1ms
    ​
    #指定客户端
    spring.redis.client-type = jedis
    

     

  • 断点调试 redisTemplate的connectionFactory实现

image.png

《小滴课堂-Redis6学习笔记》