使用IntelliJ IDEA实现SpringBoot集成Redis及高并发下缓存穿透问题处理

1. 在pom.xml文件中配置相关依赖:

        <!-- 加载MyBatis整合SpringBoot -->
        <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

2. 在Springboot核心配置文件application.properties中配置redis连接信息:

# 配置 Redis 连接信息
spring.redis.host=localhost
spring.redis.port=6379
#spring.redis.password=

3. 在需要操作redis的类中注入redisTemplate:

package com.sztxtech.springbootmybatis.service.impl;

import com.sztxtech.springbootmybatis.entity.User;
import com.sztxtech.springbootmybatis.mapper.UserMapper;
import com.sztxtech.springbootmybatis.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserMapper mapper;

    /**  注入SpringBoot自动配置好的 RedisTemplate */
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    /**
     * 查询所有用户信息
     * @return
     */
    public List<User> findAllUserInfo(){
        // 查询Redis缓存
        List<User> userList = (List<User>) redisTemplate.opsForValue().get("allUser");

        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值