springboot对连接池的使用非常智能,配置文件中添加lettuce.pool相关配置,则会使用到lettuce连接池,并将相关配置设置为连接池相关参数,(前提是这些参数是springboot配置文件中内置的,使用自定义参数应该也是可以的,有时间在研究),否则不使用,通过断点调试查看

如过使用redis连接池(无论lettuce还是jedis客户端,都需要),则需要导入如下依赖

 <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>

一、使用lettuce连接池

server.ip=192.168.102.186

spring.redis.host=${server.ip}
spring.redis.port=6379
spring.redis.timeout=20000
spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.min-idle=10
spring.redis.lettuce.pool.max-active=20
spring.redis.lettuce.pool.max-wait=10000

查看connectionFactory中相关参数

maxIdle和minIdle均为10,maxTotal为20(对应配置中max-active),maxWaitMillis为10000(对应配置中max-wait),与设置一致

查看org.apache.commons.pool2.impl.GenericObjectPoolConfig源码,如下几个字段需要注意

public class GenericObjectPoolConfig<T> extends BaseObjectPoolConfig<T> {

    /**
* The default value for the {@code maxTotal} configuration attribute.
* @see GenericObjectPool#getMaxTotal()
*/
public static final int DEFAULT_MAX_TOTAL = 8; /**
* The default value for the {@code maxIdle} configuration attribute.
* @see GenericObjectPool#getMaxIdle()
*/
public static final int DEFAULT_MAX_IDLE = 8; /**
* The default value for the {@code minIdle} configuration attribute.
* @see GenericObjectPool#getMinIdle()
*/
public static final int DEFAULT_MIN_IDLE = 0; private int maxTotal = DEFAULT_MAX_TOTAL; private int maxIdle = DEFAULT_MAX_IDLE; private int minIdle = DEFAULT_MIN_IDLE; /**
* Get the value for the {@code maxTotal} configuration attribute
* for pools created with this configuration instance.
*
* @return The current setting of {@code maxTotal} for this
* configuration instance
*
* @see GenericObjectPool#getMaxTotal()
*/
public int getMaxTotal() {
return maxTotal;
} /**
* Set the value for the {@code maxTotal} configuration attribute for
* pools created with this configuration instance.
*
* @param maxTotal The new setting of {@code maxTotal}
* for this configuration instance
*
* @see GenericObjectPool#setMaxTotal(int)
*/
public void setMaxTotal(final int maxTotal) {
this.maxTotal = maxTotal;
} .....

默认maxIdle为8,minIdle为0,maxTotal为8

查看GenericObjectPoolConfig父类BaseObjectPoolConfig

public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Cloneable {

    /**
* The default value for the {@code lifo} configuration attribute.
* @see GenericObjectPool#getLifo()
* @see GenericKeyedObjectPool#getLifo()
*/
public static final boolean DEFAULT_LIFO = true; /**
* The default value for the {@code fairness} configuration attribute.
* @see GenericObjectPool#getFairness()
* @see GenericKeyedObjectPool#getFairness()
*/
public static final boolean DEFAULT_FAIRNESS = false; /**
* The default value for the {@code maxWait} configuration attribute.
* @see GenericObjectPool#getMaxWaitMillis()
* @see GenericKeyedObjectPool#getMaxWaitMillis()
*/
public static final long DEFAULT_MAX_WAIT_MILLIS = -1L; ......

maxWaitMillis默认值为-1

二、去掉lettuce pool相关配置

connectionProvider下已经不存在poolConfig,说明未使用连接池

springboot使用lettuce连接池的更多相关文章

  1. SpringBoot 基于lettuce 连接池 配置redis多数据源操作 生产配置

    添加pom<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons- ...

  2. springboot整合druid连接池、mybatis实现多数据源动态切换

    demo环境: JDK 1.8 ,Spring boot 1.5.14 一 整合durid 1.添加druid连接池maven依赖 <dependency> <groupId> ...

  3. SpringBoot 使用Hikaricp连接池

    1.添加pom.xml依赖 如果是SpringBoot2.0,那么默认的连接池就是Hikaricp,不需要配置 其他的,如果继承 <parent> <groupId>org.s ...

  4. springboot缓存及连接池配置

    参见https://coding.imooc.com/lesson/117.html#mid=6412 1.springboot的springweb自己默认以及配置好了缓存,只需要在主文件(XxxAp ...

  5. SpringBoot Beans定义 连接池

    SpringBoot Beans定义 原有Spring框架,定义Bean方法如下 xml配置 组件扫描.@Controller.@Service... 原有Spring框架,参数注入方法如下 常用的参 ...

  6. springboot使用druid连接池连接Oracle数据库的基本配置

    #阿里连接池配置 #spring.datasource.druid.driver-class-name=oracle.jdbc.driver.OracleDriver #可配可不配,阿里的数据库连接池 ...

  7. SpringBoot下Druid连接池的使用配置

    Druid是一个JDBC组件,druid 是阿里开源在 github 上面的数据库连接池,它包括三部分: * DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体 ...

  8. springboot集成druid连接池

    使用druid连接池主要有几步: 1.添加jar和依赖 <groupId>org.mybatis.spring.boot</groupId> <artifactId> ...

  9. SpringBoot 使用Druid连接池

    1.pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

随机推荐

  1. css 表单标签两端对齐

    来自:http://demo.doyoe.com/css3/justify/justify-form.htm  侵删 <!DOCTYPE html> <html lang=" ...

  2. 求二叉树第n层节点数

    在知乎看到今日头条的一个面试题“求二叉树第n层节点数”:https://zhuanlan.zhihu.com/p/25671699,想到了这样一个解法,欢迎大家交流 我的解法采用递归的思想,从0层开始 ...

  3. <自动化测试方案_3>第三章、怎么样实现自动化测试?(How)

    第三章.怎么样实现自动化测试?(How) 自动化测试分为:代码单元自动化测试.API接口自动化测试.UI自动化测试 代码单元自动化测试,一般是无法做到的,因为项目的原因,代码单元是不做自动化,其测试是 ...

  4. python 画个小猪佩奇

    不知道大家小时候有没有学习过logo语言,就是操纵一只小王八,来画各种图案.博主小学微机课就学习了这个,最近发现python的turtle包就是logo语言,所以画个小猪佩奇和大家分享. 代码来自知乎 ...

  5. Scala链式编程内幕

    package big.data.analyse.scala /** * 链式编程原理 * Created by zhen on 2018/12/16. */ class Computer{def c ...

  6. ERROR 1044 (42000): Access denied for user 'root'@'localhost'

    从供应商那边接手一个MySQL数据库(数据库版本为5.7.21 MySQL Community Server (GPL)),在创建账号时遇到了"ERROR 1044 (42000): Acc ...

  7. C#-hello world(二)

     1.C# 程序构成 命名空间(Namespace) 一个 class Class 方法 Class 属性 一个 Main 方法 语句(Statements)和 表达式(Expressions) 注释 ...

  8. a标签的使用

    a标签可以用来跳转页面请求路径,也可以用来绑定事件. 在绑定事件的时候,我需要控制a标签,不让他进行跳转. 这时候我要做的就是限制他,不让他跳转. 只需要在href属性中加入javascript:vo ...

  9. uv-pv-vv的区别

    UV(unique visitor) 是指自然人登录自己账号访问量 KPI是指UV PV (Page View) 是指网页的浏览量 vv(Visitor view) 是指每次登录网站的访问次数 uv- ...

  10. js 实现动态时间

    <span id="timebox"></span>                   //承载时间的span $(function () { var o ...