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. ACL技术总结

    1.ACL的全称是访问控制列表,本质上是定义一组策略,以便指导报文在交换机内部的转发行为. 2.要配置策略,首先要明确ACL应用的对象,可以是针对端口,也可以是针对特殊的一条流. 针对端口,就是指端口 ...

  2. 小程序实践(六):view内部组件排版

    涉及知识点: 1.垂直排列,水平排列 2.居中对齐 示例: 1.默认排版 , 一个父组件里面两个子view 显示效果: 2.先给父view设置一个高度和颜色值,用于看效果 3.实现水平排列和垂直排列的 ...

  3. 前端 CSS预处理器Less

    引文 Less是一种动态的样式语言.Less扩展了CSS的动态行为,比如说,设置变量(Variables).混合书写模式(Mixins).操作(Operations)和功能(Functions)等等, ...

  4. c#qq发邮件

    // SMTP(Simple Mail Transport Protocol)简单邮件传输协议.在.NET Frameword类库中提供SmtpClient类(System.Net.Mail),她提供 ...

  5. Linux atop 监控系统状态

    atop是一个功能非常强大的linux服务器监控工具,它的数据采集主要包括:CPU.内存.磁盘.网络.进程等,并且内容非常的详细,特别是当那一部分存在压力它会以特殊的颜色进行展示,如果颜色是红色那么说 ...

  6. eclipse版本对应名称以及下载地址

        Eclipse 1.0         2001年11月7日(Win32/Linux32 Motif) Eclipse 2.0         2002年6月27日(Linux32 Motif ...

  7. Python3 Selenium多窗口切换

    Python3 Selenium多窗口切换 以腾讯网(http://www.qq.com/)为例,打开腾讯网,点击新闻,打开腾讯新闻,点击新闻中第一个新闻链接. 在WebDriver中封装了获取当前窗 ...

  8. C++多线程同步技巧(四)--- 信号量

    简介 信号量是维护0到指定最大值之间的同步对象.信号量状态在其计数大于0时是有信号的,而其计数是0时是无信号的.信号量对象在控制上可以支持有限数量共享资源的访问,可以用于线程同步,预防死锁等领域. 信 ...

  9. Linux:固定 ip

    默认情况下,安装完操作系统时,ip是采用dhcp来动态分配的.通常我们需要将其固定下来. 不然 每次系统重启后,ip都会变动,这样会给日常工作带来不必要的麻烦的. 下面就是在rhel .centos  ...

  10. Windows 下自动同步文件夹内容到另一个文件夹下

    实现windows 使用bat脚本文件,复制文件夹到另一个盘,参考如下代码:/y是可以不显示:提示你需要覆盖一个文件,如下图: bat文件内容为 @echo off echo "使用bat脚 ...