首页数据添加redis缓存

1、springboot整合redis

(1)在common引入redis依赖

java 复制代码
<!-- redis -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- spring2.X集成redis所需common-pool2-->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>2.6.0</version>
</dependency>

(2)编写redis配置类,配置redis相关插件

(3)在service_cms模块配置文件中添加redis配置

java 复制代码
spring.redis.host=你自己的虚拟机ip
spring.redis.port=6379
spring.redis.database= 0
spring.redis.timeout=1800000

spring.redis.lettuce.pool.max-active=20
spring.redis.lettuce.pool.max-wait=-1
#最大阻塞等待时间(负数表示没限制)
spring.redis.lettuce.pool.max-idle=5
spring.redis.lettuce.pool.min-idle=0

(4)在具体功能上添加 查询功能,先查询缓存,没有,之后查询数据库,缓存中存储数据

java 复制代码
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {
    //前台查询banner
    //value::key  banner::selectIndexList
    @Cacheable(value = "banner",key = "'selectIndexList'")
    @Override
    public List<Banner> getAllBanner() {
        List<Banner> bannerList = baseMapper.selectList(null);
        return bannerList;
    }
}
java 复制代码
*数据库写操作时,不需要同步更新redis缓存,把写操作数据在缓存中删除
*再次查询时,走完整更新缓存步骤
相关推荐
沃达德软件2 分钟前
重点人员动态管控系统解析
数据仓库·人工智能·hive·hadoop·redis·hbase
daols885 分钟前
vue2 甘特图 vxe-gantt 一行渲染多个子任务的配置
vue.js·甘特图·vxe-table
码界奇点15 分钟前
基于Spring Boot和Vue3的无头内容管理系统设计与实现
java·spring boot·后端·vue·毕业设计·源代码管理
heartbeat..1 小时前
Redis 中的锁:核心实现、类型与最佳实践
java·数据库·redis·缓存·并发
Prince-Peng1 小时前
技术架构系列 - 详解Redis
数据结构·数据库·redis·分布式·缓存·中间件·架构
虾说羊1 小时前
redis中的哨兵机制
数据库·redis·缓存
To Be Clean Coder1 小时前
【Spring源码】createBean如何寻找构造器(二)——单参数构造器的场景
java·后端·spring
你才是臭弟弟1 小时前
SpringBoot 集成MinIo(根据上传文件.后缀自动归类)
java·spring boot·后端
C澒2 小时前
面单打印服务的监控检查事项
前端·后端·安全·运维开发·交通物流
pas1362 小时前
39-mini-vue 实现解析 text 功能
前端·javascript·vue.js