缓存redis

对于从来没用过redis的人不要慌,没用过之前我也不知道redis是个啥东西,用过一次之后,哇哦

        
			redis.clients
			jedis
			2.9.0
		

		
			org.springframework.boot
			spring-boot-starter-data-redis
			1.5.2.RELEASE
		

首先在pom文件里添加依赖

redis:
        host:  localhost
        port:  6379
        password:
        pool:
           max-wait: -1
           max-total: 8
           max-idle: 8
           min-idle: 0
        timeout: 5000

然后在yml配置文件里配置redis

@Service(value = "lgtMemberInfoService")
public class LgtMemberInfoServiceImpl implements LgtMemberInfoService {
    private static final String KEY = "KEY";

    @Autowired
    private LgtMemberInfoEntityMapper lgtMemberInfoEntityMapper;
    @Resource(name = "redisTemplate")
    private RedisTemplate> redisTemplate;

    @Override
    @Scheduled(cron = "0/5 * * * * ?")
//    @Scheduled(cron="0 3 * * * ?")
    public void selectLgtMemberInfo() {
        Date now = new Date();
        DateFormat df = DateFormat.getDateInstance();
        String key = df.format(now);
        List list = lgtMemberInfoEntityMapper.selectAll();
        ValueOperations> vOps = redisTemplate.opsForValue();
        vOps.set(key,list);
    }
}

用法就是这么简单,注意泛型就好

你可能感兴趣的:(缓存redis)