聊聊spring-boot-starter-data-redis的配置变更


本文主要研究一下spring-boot-starter-data-redis的配置变更

配置变更

以前是spring-boot的1.4.x版本的(spring-data-redis为1.7.x版本),最近切到2.0.4.RELEASEB版本(spring-data-redis为2.0.5.RELEASE版本),发现配置有变更。

旧版配置

spring.redis.database=0
spring.redis.host=192.168.99.100
spring.redis.port=6379
#spring.redis.password= # Login password of the redis server. spring.redis.pool.max-active=8 spring.redis.pool.max-idle=8 spring.redis.pool.max-wait=-1 spring.redis.pool.min-idle=0 #spring.redis.sentinel.master= # Name of Redis server. #spring.redis.sentinel.nodes= # Comma-separated list of host:port pairs. spring.redis.timeout=10

新版本配置

spring.redis.database=0
spring.redis.host=192.168.99.100
spring.redis.port=6379
#spring.redis.password= # Login password of the redis server. spring.redis.lettuce.pool.max-active=8 spring.redis.lettuce.pool.max-idle=8 spring.redis.lettuce.pool.max-wait=-1ms spring.redis.lettuce.pool.min-idle=0 #spring.redis.sentinel.master= # Name of Redis server. #spring.redis.sentinel.nodes= # Comma-separated list of host:port pairs. spring.redis.timeout=100ms

小结

新版spring-boot-starter-data-redis有几个变更如下:

  • spring.redis底下除了公共的配置外,区分两个不同的实现,jedis及lettuce
  • 公共配置spring.redis.timeout的参数改为Duration类型,需要增加时间单位参数
  • spring-boot-starter-data-redis新版默认是使用lettuce
  • redis连接池需要引入commons-pool2类库,由于该类库新版本的一些核心类有变动,因此需要注意下版本号,超过2.4.3版本的可能会有问题


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM