SpringBoot 集成 Redis

SpringBoot 2.3.1

添加依赖

这里我们采用的是 lettuce 所以必须引入commons-pool2

 <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: 127.0.0.1
    port: 6379
    database: 0
#    password:
    timeout: 6000
# 链接池
    lettuce:
      pool:
        max-active: 10
        max-idle: 10
        max-wait: 0

自定义 RedisConfiguration

自定义 RedisUtil

这里只截取了一部分,更多的源码请移步source-code 内的redis 目录

测试

Last updated

Was this helpful?