私人vps网站的redis如何做多字段排序
云服务器
私人vps网站的redis如何做多字段排序
2026-01-21 15:03
私人vps网站的redis做多字段排序的示例:
在redis编辑器中添加以下代码:
packagecom.example.demo;
importcom.example.demo.common.Constant;
importcom.example.demo.mapper.QuestionAnswerHistoryMapper;
importcom.example.demo.model.QuestionAnswerHistory;
importcom.example.demo.service.QuestionAnswerHistoryService;
importcom.example.demo.thread.BaseTest;
importorg.apache.commons.lang3.RandomUtils;
importorg.junit.Test;
importorg.springframework.beans.factory.annotation.Autowired;
importjava.math.BigDecimal;
importjava.util.List;
/**
*@authorwzx
*@time2019/6/16
*/
publicclassQuestionAnswerHistoryTestextendsBaseTest{
@Autowired
privateQuestionAnswerHistoryMapperhistoryMapper;
@Autowired
privateQuestionAnswerHistoryServicehistoryService;
@Test
publicvoidtest(){
for(inti=1;i<101;i++){
QuestionAnswerHistoryhistory=newQuestionAnswerHistory();
history.setUserId((long)i);
history.setAnswerFinish(true);
BigDecimalbigDecimal=BigDecimal.valueOf(RandomUtils.nextDouble(0,1))
.setScale(2,BigDecimal.ROUND_HALF_UP);
history.setCorrectRate(bigDecimal.doubleValue());
history.setTimeConsumed(RandomUtils.nextInt(15,50));
history.setTimeConsumedMillisecond(RandomUtils.nextInt(0,1000));
history.setStatus(Constant.GenerictStatus.NORMAL);
historyMapper.insert(history);
}
}
@Test
publicvoidqueryRanking(){
Listranking=historyService.getRanking();
for(QuestionAnswerHistoryhistory:ranking){
System.out.println(history.getUserId()+"\t"+history.getCorrectRate()+"\t"+history.getTimeConsumed()+
"\t"+history.getTimeConsumedMillisecond());
}
}
@Test
publicvoidupdateRank(){
LonguserId=25L;
//生成新的答题记录
QuestionAnswerHistoryhistory=newQuestionAnswerHistory();
history.setUserId(userId);
history.setAnswerFinish(true);
BigDecimalbigDecimal=BigDecimal.valueOf(RandomUtils.nextDouble(0,1))
.setScale(2,BigDecimal.ROUND_HALF_UP);
history.setCorrectRate(bigDecimal.doubleValue());
history.setTimeConsumed(RandomUtils.nextInt(15,50));
history.setTimeConsumedMillisecond(RandomUtils.nextInt(0,1000));
history.setStatus(Constant.GenerictStatus.NORMAL);
historyService.updateRank(history);
}
}
输入结果:
id正确率耗时
740.9438151
370.9316802
970.9231475
630.923674
350.9239516
850.9239525
170.919821
550.935268
640.893739
190.8843350
490.8625373
780.8642296
760.8419399
210.8438365
540.83267
700.7930213
200.7818112
460.7824789
270.7623195
330.7629414
70.7520661
一诺网络提供的私人vps,是一款弹性计算服务类产品,其功能基本上与传统的x86物理服务器相当,具备分钟级交付效率,可快速部署和创建所需要的业务应用环境,服务器资源和配置支持弹性伸缩;拥有管理便捷、易于操作等诸多优点。可以极大降低用户的IT使用成本,用户无需亲自搭建基础设施、简化了运维和管理的日常工作量,使得用户能够更专注于自身的业务发展和创新。