redis 如何使用?

jeecg-boot集成了redis

用法分三种:

  • 通过Jeecg自封装工具类
  1. //封装了redis操作各种方法
  2. @Autowired
  3. private RedisUtil redisUtil;

2.通过注解参考链接: https://www.cnblogs.com/fashflying/p/6908028.html

  1. //key的定义参考官方文档
  2. @Cacheable(cacheNames="jeecgDemo", key="#id")
  3. 示例:
  4. /**
  5. * 缓存注解测试: redis
  6. */
  7. @Cacheable(cacheNames="jeecgDemo", key="#id")
  8. public JeecgDemo getByIdCacheable(String id) {
  9. JeecgDemo t = jeecgDemoMapper.selectById(id);
  10. System.err.println(t);
  11. return t;
  12. }

3.通过原生工具service

  1. @Autowired
  2. private RedisTemplate<String, Object> redisTemplate;
  3. @Autowired
  4. private StringRedisTemplate stringRedisTemplate;

其他技巧:@CacheEvict用来标注在需要清除缓存元素的方法或类上的参考链接: https://www.cnblogs.com/fashflying/p/6908028.html

  1. @CacheEvict(value="dictCache", allEntries=true)
  2. public Result<SysDict> delete(@RequestParam(name="id",required=true) String id) {