修改排队位置

This commit is contained in:
2024-01-25 14:11:12 +08:00
parent e90c4f7239
commit aa270b5f7d

View File

@@ -360,6 +360,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
@Override @Override
public Long getRankPosition(String uniqueId) { public Long getRankPosition(String uniqueId) {
// rank 从0开始
return redisUtil.getRank(consumptionOrderKey, uniqueId); return redisUtil.getRank(consumptionOrderKey, uniqueId);
} }
@@ -374,8 +375,10 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
// 2、判断该请求是否还在排队 // 2、判断该请求是否还在排队
Boolean existsInZSet = redisUtil.isElementExistsInZSet(consumptionOrderKey, uniqueId); Boolean existsInZSet = redisUtil.isElementExistsInZSet(consumptionOrderKey, uniqueId);
if (existsInZSet) { if (existsInZSet) {
// 排队中,给出当前排序位置 // 排队中,给出当前排序位置,rank从0开始
return new GenerateCollectionVO(getRankPosition(uniqueId) + 1L); Long rankPosition = getRankPosition(uniqueId);
// 有9个消费者所以当rank>8即当前请求至少排在第九位时其实际排队位置为9-8+1当rank <=8请求均在处理中
return new GenerateCollectionVO( rankPosition > 8L ? rankPosition - 8 + 1 : 1L);
} }
// 3、判断redis中有没有 // 3、判断redis中有没有