美文网首页
Redis设置List集合过期时间

Redis设置List集合过期时间

作者: Buckler | 来源:发表于2020-07-27 10:38 被阅读0次

可以使用expire对key进行getset操作,也可以通过key设置过期时间

    @GetMapping("/api/findalluserinfo")
    public Object findAll() {
        if (redisTemplate.hasKey("alluser")) {
            System.out.println("cache");
        } else {
            List<UserInfo> userinfoList = iUserInfo.findAll();
            ListOperations<String, Object> lo = redisTemplate.opsForList();
            lo.rightPush("alluser", userinfoList);
            redisTemplate.expire("alluser", 60, TimeUnit.SECONDS);
        }
        return redisTemplate.opsForList().range("alluser", 0, -1);
    }

相关文章

网友评论

      本文标题:Redis设置List集合过期时间

      本文链接:https://www.haomeiwen.com/subject/qkzalktx.html