1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @RestController @RequestMapping("/kind") public class KindController {
@Autowired private KindService kindService;
@Autowired RedisTemplate redisTemplate;
static String REDIS_KIND_LIST = "kind_list"; @GetMapping("/list") public List<Kind> list(){
ListOperations listOperations = redisTemplate.opsForList(); Long size = listOperations.size(REDIS_KIND_LIST); if (size != null && size > 0){ List list = listOperations.range(REDIS_KIND_LIST, 0, size - 1); return list; }else { List<Kind> list = kindService.list(); listOperations.rightPushAll(REDIS_KIND_LIST,list); return list; }
} }
|