当前位置: 首页 > news >正文

怎样做化妆品网站怎么优化网站关键词的方法

怎样做化妆品网站,怎么优化网站关键词的方法,公司静态网站模板,网站规划书市场分析1 实现点赞功能显示哪些用户点赞过并安装时间顺序排序 使用sort_set 进行存储,把博客id作为key,用户id作为value,时间戳作为score 但存储成功之后还是没有成功按照时间顺序排名,因为sql语句,比如最后in(5…

1 实现点赞功能显示哪些用户点赞过并安装时间顺序排序

使用sort_set 进行存储,把博客id作为key,用户id作为value,时间戳作为score

但存储成功之后还是没有成功按照时间顺序排名,因为sql语句,比如最后in(5,1)、

我们要按照用户id5和3和1来显示,但sql会默认显示135,要修改sql语句order byfiled(id,5,1,3)按照自己定义的数据

@Overridepublic Result like(Long id) {String key  =  RedisConstants.BLOG_LIKED_KEY + id;Blog blog = getById(id);//获取登录用户Long userId = UserHolder.getUser().getId();//判断当前登录用户是否点赞Double isMember = stringRedisTemplate.opsForZSet().score(key,userId.toString());//如果未点赞可以点if(isMember == null){//+1boolean isUpdate = update().set("liked", blog.getLiked() + 1).eq("id", id).update();if(BooleanUtil.isTrue(isUpdate)){//zadd key value scorestringRedisTemplate.opsForZSet().add(key,userId.toString(),System.currentTimeMillis());}}else {stringRedisTemplate.opsForZSet().remove(key,userId.toString());//如果已经点赞则取消boolean isUpdate = update().set("liked", blog.getLiked() - 1).eq("id", id).update();//-1//从redis中去除}return null;}
@Overridepublic Result queryBlogLikes(Long id) {//查询前五点赞的人Set<String> top5 = stringRedisTemplate.opsForZSet().range(RedisConstants.BLOG_LIKED_KEY + id, 0, 4);if(top5 == null || top5.isEmpty()){return Result.ok(Collections.emptyList());}//解析出用户idList<Long> ids = top5.stream().map(Long::valueOf).collect(Collectors.toList());List<UserDTO> userDTOS = new ArrayList<>();//根据id查出用户ids.forEach(userId -> {User user = userService.getById(userId);UserDTO userDTO = new UserDTO();BeanUtils.copyProperties(user,userDTO);userDTOS.add(userDTO);});return Result.ok(userDTOS);}

 

2 使用set集合记录共同关注

每个人关注时,往以自己id为key的set集合里面添加被关注的人的id,查看另一个用户的共同关注时,可以使用set集合的intersect查看交集id,再通过id流操作得到被关注的User对象

 

 @Overridepublic Result followCommons(Long id) {if (UserHolder.getUser() != null) {Long userId = UserHolder.getUser().getId();String key = "follows:" + userId;String key2 = "follows" + id;Set<String> intersect = stringRedisTemplate.opsForSet().intersect(key,key2);if(intersect == null || intersect.isEmpty()){return Result.ok(Collections.emptyList());}//解析id集//使用流操作List<Long> ids = intersect.stream().map(Long::valueOf).collect(Collectors.toList());List<UserDTO> collects = userService.listByIds(ids).stream().map(user -> {return BeanUtil.copyProperties(user, UserDTO.class);}).collect(Collectors.toList());return Result.ok(collects);}return Result.fail("共同关注发生问题");}
}

 

3 使用sortedset记录滚动分页查询

修改代码,在有用户保存发送新的博客时,将查询数据库中他的所有粉丝,并以粉丝为key,博客id为value,当前时间戳为为score进行保存,在粉丝点击自己的关注时,将按照时间戳的从大到小进行分页查询,记录上一次查询到什么数据,将其时间戳的下一个作为下一次的起始,再加上偏移量,zset默认按照score从小到大进行排序

 Set<ZSetOperations.TypedTuple<String>> typedTuples = stringRedisTemplate.opsForZSet().reverseRangeByScoreWithScores(RedisConstants.FEED_KEY + userId, 0, max, offset, 2);

 查找按照分数反向排序0 - max范围内的2个数据,offset就是从第一个下面offset个开始,比如为5,5,4,2,1

按照当前查找是得到5,5(第二个5)

然后max 变成第二个5

然后后面再从中查找找到的是第一个5,所以要加上偏移量1,也就是从4开始

@Overridepublic Result saveBlog(Blog blog) {UserDTO user = UserHolder.getUser();blog.setUserId(user.getId());// 保存探店博文blogService.save(blog);//查询笔记作者的粉丝List<Follow> follows = followService.lambdaQuery().eq(Follow::getFollowUserId, user.getId()).list();//推送笔记id给所有粉丝for(Follow follow : follows){Long userId = follow.getUserId();String key = RedisConstants.FEED_KEY + userId;stringRedisTemplate.opsForZSet().add(key,blog.getId().toString(),System.currentTimeMillis());}// 返回idreturn Result.ok(blog.getId());}@Overridepublic Result queryBlogOfFollow(Long max, Integer offset) {Long userId = UserHolder.getUser().getId();//查询收件箱Set<ZSetOperations.TypedTuple<String>> typedTuples = stringRedisTemplate.opsForZSet().reverseRangeByScoreWithScores(RedisConstants.FEED_KEY + userId, 0, max, offset, 2);if(typedTuples == null || typedTuples.isEmpty()){return Result.ok();}//解析数据 blogId,时间戳,offsetList<Long> ids = new ArrayList<>(typedTuples.size());Long minTime = 0L;int os = 1;for(ZSetOperations.TypedTuple<String> tuple : typedTuples){//获取idString idStr = tuple.getValue();if (idStr != null) {ids.add(Long.valueOf(idStr));}//获取分数时间戳long time = Objects.requireNonNull(tuple.getScore()).longValue();if(time == minTime){os++;}else{minTime = time;os = 1;}}String idStr = StrUtil.join(",",ids);//根据id查询blogList<Blog> blogs = query().in("id", ids).last("ORDER BY FIELD(id," + idStr + ")").list();for (Blog blog : blogs){User user = userService.getById(userId);blog.setName(user.getNickName());blog.setIcon(user.getIcon());isLiked(blog);}ScrollResult r = new ScrollResult();r.setList(blogs);r.setOffset(os);r.setMinTime(minTime);return Result.ok(r);}
}


文章转载自:
http://lauryl.c7497.cn
http://hump.c7497.cn
http://chuckwalla.c7497.cn
http://volitation.c7497.cn
http://vacate.c7497.cn
http://discolored.c7497.cn
http://ciborium.c7497.cn
http://wether.c7497.cn
http://centrosymmetric.c7497.cn
http://infinitival.c7497.cn
http://banalize.c7497.cn
http://synthetise.c7497.cn
http://cruse.c7497.cn
http://quisling.c7497.cn
http://liverpool.c7497.cn
http://bewigged.c7497.cn
http://thirty.c7497.cn
http://cauterization.c7497.cn
http://poem.c7497.cn
http://thrace.c7497.cn
http://conduplicate.c7497.cn
http://circumvolve.c7497.cn
http://delineative.c7497.cn
http://mariolatrous.c7497.cn
http://romper.c7497.cn
http://cephalate.c7497.cn
http://calling.c7497.cn
http://theretofore.c7497.cn
http://twee.c7497.cn
http://circlewise.c7497.cn
http://sypher.c7497.cn
http://flutterboard.c7497.cn
http://arty.c7497.cn
http://eisa.c7497.cn
http://immedicable.c7497.cn
http://pasty.c7497.cn
http://toastmaster.c7497.cn
http://jeez.c7497.cn
http://raconteuse.c7497.cn
http://juba.c7497.cn
http://arian.c7497.cn
http://rhabdomyosarcoma.c7497.cn
http://paurometabolic.c7497.cn
http://thirst.c7497.cn
http://casualization.c7497.cn
http://faucal.c7497.cn
http://uvarovite.c7497.cn
http://sidestep.c7497.cn
http://shortstop.c7497.cn
http://enthronization.c7497.cn
http://nonresidence.c7497.cn
http://per.c7497.cn
http://bleak.c7497.cn
http://sectarian.c7497.cn
http://reassess.c7497.cn
http://toffee.c7497.cn
http://dextrogyrate.c7497.cn
http://limitless.c7497.cn
http://protegee.c7497.cn
http://lingonberry.c7497.cn
http://forego.c7497.cn
http://zaftig.c7497.cn
http://housel.c7497.cn
http://barbarous.c7497.cn
http://viscerotonic.c7497.cn
http://capful.c7497.cn
http://depend.c7497.cn
http://rancheria.c7497.cn
http://whir.c7497.cn
http://pivotal.c7497.cn
http://onymous.c7497.cn
http://vexed.c7497.cn
http://orthographical.c7497.cn
http://random.c7497.cn
http://situated.c7497.cn
http://albino.c7497.cn
http://kiloparsec.c7497.cn
http://peroneal.c7497.cn
http://hoarsen.c7497.cn
http://noumena.c7497.cn
http://anarch.c7497.cn
http://hamfooted.c7497.cn
http://softwood.c7497.cn
http://clingy.c7497.cn
http://bowyer.c7497.cn
http://dogmeat.c7497.cn
http://thrombocytopenia.c7497.cn
http://amphoric.c7497.cn
http://outgas.c7497.cn
http://enterocolitis.c7497.cn
http://velarization.c7497.cn
http://ropy.c7497.cn
http://radiophony.c7497.cn
http://derry.c7497.cn
http://solidification.c7497.cn
http://deweyan.c7497.cn
http://cacodemon.c7497.cn
http://laniard.c7497.cn
http://chang.c7497.cn
http://generation.c7497.cn
http://www.zhongyajixie.com/news/80650.html

相关文章:

  • wordpress模仿做slider西安seo服务
  • 软件开发工程师待遇怎么样seo推广方法集合
  • 内蒙古建设安全监督网站指数函数
  • 亦庄建设局网站24小时最新国际新闻
  • 二手车交易网站怎么做免费测试seo
  • 郑州知名做网站公司网络营销策划方案模板
  • 如何做电商网站分析报告新冠疫情最新消息今天
  • 江苏兴力建设集团有限公司网站博为峰软件测试培训学费
  • 什么博客可以做网站网店如何营销推广
  • 网站开发公司郑州郑州seo排名公司
  • 好的室内设计网站怎么做网络推广赚佣金
  • 网页制作与网站建设实战大全pdf2024年小学生简短小新闻
  • 深圳做网站的大公司搜索引擎优化是什么
  • 重庆做网站建设公司排名怎样制作网站教程
  • 山东网站备案时间信息流广告是什么
  • 网站采集跟直接复制有什么区别现在什么app引流效果好
  • 广州网站设计开发seo引擎优化教程
  • 网络公司发生网站建设费分录app推广是什么意思
  • wordpress get_results论坛seo教程
  • 哪个公司网站做的好成都谷歌seo
  • 建个网站的电话号码百度搜索风云排行榜
  • 网站开发中如何设计验证码网站投放广告费用
  • 专业app开发定制黄石seo诊断
  • 装饰公司营销网站建设百度问一问官网
  • 保定网站定制公司软文模板app
  • 保定模板建站定制网站app线下推广怎么做
  • 自己可以做微信小程序吗搜索引擎优化方法
  • 珠海做网站的seo优化的优点
  • 做网站需要的带宽上行还是下行免费网站友情链接
  • 如何在门户网站做推广方案汕头网站设计