SpringBoot整合Redis

一、引入依赖  https://mvnrepository.com/

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

二、后台代码:

spring.redis.database=0
spring.redis.host=192.168.1.xxx
spring.redis.port=8099
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.max-wait=-1ms
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.min-idle=0
spring.redis.timeout=0
spring:
  redis:
    lettuce:
      pool:
        max-active: 100  # 连接池最大连接数(使用负值表示没有限制)
        max-wait: 2000  # 连接池最大阻塞等待时间(使用负值表示没有限制),单位ms
        max-idle: 10  # 连接池中的最大空闲连接
        min-idle: 5 # 连接池中的最小空闲连接
        test-on-borrow: true
    host:  127.0.0.1
    port:  6379
    password: '123456'
    timeout: 2000
    enable: true
    database: 14
  cache: redis
@Controller
@Api(tags = "书本数据接口")
@EnableCaching//开启缓存
public class BookController {

}
  @Cacheable(value = "book_id")//使用缓存
    @Override
    public Book getBookById(Integer id) {
        System.out.println("从数据库中查询。。。。。");
        return bookMapper.getBookById(id);
    }
原文地址:https://www.cnblogs.com/mingforyou/p/14655737.html