SpringBoot 简单整合Redis (超简单)

1:添加依赖

      <!-- redis -->

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

2:yml 文件简单配置

spring:
  application:
    name: demoTest
  redis:
    host: xxx.xxx.xxx.xxx
    port: 6379
    lettuce:
      pool:
        max-active: 8 # 最大连接
        max-idle: 8 # 最大空闲连接
        min-idle: 0 # 最小空闲连接
        max-wait: 100ms # 连接等待时间

3:测试看是否成功

bd96524e9f9e4fc59f9a5914ea99add1.png

4:注意需要添加这个依赖 

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

否则启动项目会报:

Error creating bean with name 'redisTemplate' defined in class path resource  

 

posted @ 2023-02-13 14:16  wode林夕  阅读(14)  评论(0编辑  收藏  举报  来源