亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

redis如何做多字段排序

小新
438
2020-12-14 13:24:54
欄目: 云計算

redis如何做多字段排序

redis做多字段排序的示例:

在redis編輯器中添加以下代碼:

package com.example.demo;

import com.example.demo.common.Constant;

import com.example.demo.mapper.QuestionAnswerHistoryMapper;

import com.example.demo.model.QuestionAnswerHistory;

import com.example.demo.service.QuestionAnswerHistoryService;

import com.example.demo.thread.BaseTest;

import org.apache.commons.lang3.RandomUtils;

import org.junit.Test;

import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

import java.util.List;

/**

* @author wzx

* @time 2019/6/16

*/

public class QuestionAnswerHistoryTest extends BaseTest {

@Autowired

private QuestionAnswerHistoryMapper historyMapper;

@Autowired

private QuestionAnswerHistoryService historyService;

@Test

public void test() {

for (int i = 1; i < 101; i++) {

QuestionAnswerHistory history = new QuestionAnswerHistory();

history.setUserId((long) i);

history.setAnswerFinish(true);

BigDecimal bigDecimal = 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

public void queryRanking() {

Listranking = historyService.getRanking();

for (QuestionAnswerHistory history : ranking) {

System.out.println(history.getUserId() + "\t" + history.getCorrectRate() + "\t" + history.getTimeConsumed() +

"\t" + history.getTimeConsumedMillisecond());

}

}

@Test

public void updateRank() {

Long userId = 25L;

//生成新的答題記錄

QuestionAnswerHistory history = new QuestionAnswerHistory();

history.setUserId(userId);

history.setAnswerFinish(true);

BigDecimal bigDecimal = 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 正確率 耗時

74 0.94 38 151

37 0.93 16 802

97 0.92 31 475

63 0.92 36 74

35 0.92 39 516

85 0.92 39 525

17 0.9 19 821

55 0.9 35 268

64 0.89 37 39

19 0.88 43 350

49 0.86 25 373

78 0.86 42 296

76 0.84 19 399

21 0.84 38 365

54 0.83 26 7

70 0.79 30 213

20 0.78 18 112

46 0.78 24 789

27 0.76 23 195

33 0.76 29 414

7 0.75 20 661

0
英吉沙县| 刚察县| 高清| 山东| 东乡族自治县| 六枝特区| 丰原市| 大英县| 武山县| 白水县| 绥阳县| 德清县| 邢台县| 乌鲁木齐市| 石嘴山市| 安丘市| 芒康县| 娄烦县| 宁德市| 什邡市| 尼木县| 赤峰市| 英山县| 三台县| 乐亭县| 沙坪坝区| 清苑县| 天峨县| 本溪| 高雄县| 宁化县| 图木舒克市| 奈曼旗| 盘山县| 新和县| 永修县| 磐石市| 三穗县| 阜南县| 内江市| 阜宁县|