一、什么是热点数据
在很短的时间内,许多数据要被多次查询(像双十一购物,查询商品)
二、为什么要使用redis
redis是非关系型数据库,Redis将数据存储在内存上,避免了频繁的IO操作
三、场景
短时间内有大量的请求来获取用户列表的数据,每次都需要从数据库进行查询。
处理热点数据的基本思路:用户首次访问从数据库中取值,之后每次进行判断只要redis中有数据,就从redis中取值,其中涉及到多线程访问造成的内存穿透问题,采用双重检查的形式解决。
package com.abbey.myblog.service;
import com.abbey.myblog.mapper.UserMapper;
import com.abbey.myblog.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Service;
/**
* @author lianying
* @create 2020-11-21 9:02 下午
**/
@Service
public class UserService {