180  
查询码:00000150
springboot 使用集中式缓存Redis
作者: 倪嗣成 于 2020年12月25日 发布在分类 / 物联网组 / 边缘接入网关 下,并于 2020年12月25日 编辑
redis

第一步 pom.xml中增加相关依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>
第二步 :配置文件中增加配置信息,以本地运行为例,比如:

spring.redis.host=localhost
spring.redis.port=6379
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-wait=-1ms
spring.redis.lettuce.pool.min-idle=0
spring.redis.lettuce.shutdown-timeout=100ms

关于连接池的配置,注意几点:

  1. Redis的连接池配置在1.x版本中前缀为spring.redis.pool与Spring Boot 2.x有所不同。
  2. 在1.x版本中采用jedis作为连接池,而在2.x版本中采用了lettuce作为连接池



 推荐知识

 历史版本

修改日期 修改人 备注
2020-12-25 14:18:14[当前版本] 倪嗣成 创建版本

知识分享平台 -V 4.8.7 -wcp