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

html5网站制作产品质量推广营销语

html5网站制作,产品质量推广营销语,网站开发招标技术要求,老哥们给个uc能看的本文主要介绍 redis 缓存在线上的使用场景 由于业务的特殊性,在生产库用户表中,大概有 50 多万的测试用户,在真实业务计算中,要把测试用户给筛选掉,所以在计算前,需要把测试用户加载到 redis 缓存中&#x…

本文主要介绍 redis 缓存在线上的使用场景

由于业务的特殊性,在生产库用户表中,大概有 50 多万的测试用户,在真实业务计算中,要把测试用户给筛选掉,所以在计算前,需要把测试用户加载到 redis 缓存中,并构建本地缓存。

查询数据库

为了提高查询效率,先得到最大主键ID,以每次查询5000 条提前构建好批次范围,并采用并行查询的方式。

     long maxUserId = odsUserDAO.getMaxUserId(); // 查询最大 id// 构建批次范围列表List<LinkedList<Long>> pagingIntervalList = new ArrayList<>();//初始化分页列表for(long leftBoundary = 0; leftBoundary < maxUserId; leftBoundary += 5000){LinkedList<Long> pagingInterval = new LinkedList<>();long rightBoundary = leftBoundary + 5000;if(rightBoundary >= maxUserId){pagingInterval.add(leftBoundary);pagingInterval.add(maxUserId + 1);pagingIntervalList.add(pagingInterval);break;}pagingInterval.add(leftBoundary);pagingInterval.add(rightBoundary);pagingIntervalList.add(pagingInterval);}//并行加载测试学生Set<Long> testUserIdSet = pagingIntervalList.parallelStream().map(pagingInterval -> odsUserDAO.incrementGetTestUser(pagingInterval.peekFirst(), pagingInterval.peekLast())).flatMap(List::stream).map(o -> o.getId()).collect(Collectors.toSet());

分页查询 sql

<select id="incrementGetTestUser" resultMap="BaseResultMap">select  <include refid="Base_Column_List"/>from userwhere (account_type ='TEST'or name like '%test%'or name like '%TEST%'or name like '%测试%'or status <![CDATA[ <> ]]> 'NORMAL')and id between #{pagingStartIdx} and #{pagingEndIdx}and status = 1</select>

写回缓存

private static volatile Set<Long> testUserLocalCache = null; //全局变量testUserLocalCache = testUserIdSet; //本地缓存
String[] testUserIdArray = testUserIdSet.parallelStream().map(String::valueOf).toArray(String[]::new);
redisCluster.sadd("test_user_data", testUserIdArray); //redis缓存

查询缓存

在处理业务时,如果该用户是测试数据,则跳过。

private static volatile Set<Long> testUserLocalCache = null; //全局变量public boolean isTestUser(Long userId){if (testUserLocalCache == null || testUserLocalCache.isEmpty()){boolean isRemoteTestUserCacheExists = redisCluster.exists("test_user_data");if(!isRemoteTestUserCacheExists){throw new RuntimeException("failed to hit test user remote cache, cause test user never preload");}// 如果本地缓存为空,则构建synchronized(this){if (testUserLocalCache == null || testUserLocalCache.isEmpty()){Set<String> testUserSet = redisCluster.sscanAll("test_user_data"); //采用 sscan 游标方式查询testUserLocalCache = testUserSet.parallelStream().map(Long::valueOf).collect(Collectors.toSet());}}}//从本地缓存查询数据return testUserLocalCache.contains(userId);}

总结

由于业务性质及生产机器配置够高,缓存不设置过期时间,只是在下次计算前,先清除缓存即可,再构建本次新的缓存。

http://www.hkea.cn/news/971003/

相关文章:

  • 广东做网站公司广州从化发布
  • 能发外链的网站国际新闻今天最新消息
  • 做软件的网站关键词优化快速排名
  • 网站建设与管理简介网站链接交易
  • 英文网站建设教程网盘资源搜索神器
  • 做旅游网站的引言最新网络推广平台
  • 服务器上给网站做301跳转企业网站注册
  • 网站建设好做吗乐事薯片软文推广
  • wordpress 年月归档如何优化培训体系
  • 威海高区建设局网站长春做网络优化的公司
  • 安平做网站百度一下首页百度一下知道
  • 苏州建设网站市政中标项目如何做推广引流赚钱
  • 17网站一起做网店怎么下单来宾网站seo
  • 建设商务网站的目的天津seo网站排名优化公司
  • 阿里巴巴网站导航栏怎么做口碑营销策划方案
  • 线上做交互的网站百度app下载
  • 做暖暖欧美网站挖掘爱站网
  • 网站 风格百度推广公司
  • 林州网站建设公司站长工具关键词排名怎么查
  • 想给公司做个网站微信seo是什么意思
  • 网站做管制户外刀具营销推广方案模板
  • 淘宝客网站免费做seo网站关键词优化机构
  • 企业做网站建设的好处seo网站关键词优化
  • 一般网站用什么做的最新新闻国内大事件
  • 做线上网站需要钱吗互联网营销推广
  • 找个美工做淘宝网站需要多少钱南昌seo方案
  • 网站用户登录流程图外贸高端网站设计公司
  • 做搜狗手机网站优化软代写
  • wordpress页面背景颜色win7优化设置
  • 做分类信息网站代码百度搜索推广优化师工作内容