修改排队位置
This commit is contained in:
@@ -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中有没有
|
||||||
|
|||||||
Reference in New Issue
Block a user