代码拉取完成,页面将自动刷新
//从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);
这个依旧会出现几个人同时点赞,数量只加一次的情况吧