544 Star 7.3K Fork 2.9K

陌溪 / 蘑菇博客

 / 详情

点击数更新不正确的情况

已完成
创建于  
2022-08-23 22:05

参考文档

输入图片说明

//从Redis取出数据,判断该用户是否点击过
String jsonResult = stringRedisTemplate.opsForValue().get("BLOG_CLICK:" + ip + "#" + blog.getUid());

    if (StringUtils.isEmpty(jsonResult)) {

        //给博客点击数增加
        Integer clickCount = blog.getClickCount() + 1;
        blog.setClickCount(clickCount);
        blog.updateById();

        //将该用户点击记录存储到redis中, 24小时后过期
        stringRedisTemplate.opsForValue().set(RedisConf.BLOG_CLICK + Constants.SYMBOL_COLON + ip + Constants.SYMBOL_WELL + blog.getUid(), blog.getClickCount().toString(),
                24, TimeUnit.HOURS);
    }
    return ResultUtil.result(SysConf.SUCCESS, blog);

这个依旧会出现几个人同时点赞,数量只加一次的情况吧

评论 (1)

Tyrion 创建了任务

可以通过将这三步进行加锁解决,不过点击数增加,并不是一个特别重要的参数,就没加限制

陌溪 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
848486 moxi159753 1578933786 7792101 tyrion777 1666690095
Java
1
https://gitee.com/moxi159753/mogu_blog_v2.git
git@gitee.com:moxi159753/mogu_blog_v2.git
moxi159753
mogu_blog_v2
蘑菇博客

搜索帮助

53164aa7 5694891 3bd8fe86 5694891