优化随机查询云仓商品
This commit is contained in:
parent
8f7da59b5d
commit
a36a775db4
@ -225,19 +225,18 @@ class SpuRepository extends BaseRepository
|
||||
$dataKey = 'CloudMerchantSpu_' . $merId;
|
||||
$takenKey = 'CloudMerchantSpuTakenProductIds_' . $merId . '_page_'. $page;
|
||||
$RedisCacheService = app()->make(RedisCacheService::class);
|
||||
if (!$RedisCacheService->exists($takenKey)) {
|
||||
$productIds = $RedisCacheService->sRandMember($dataKey, 10);
|
||||
} else {
|
||||
$keys = $RedisCacheService->sDiff($dataKey, $takenKey);
|
||||
$number = min(count($keys), 10);
|
||||
if ($number <= 0) {
|
||||
return [];
|
||||
}
|
||||
$indexes = array_rand($keys, $number);
|
||||
$productIds = [];
|
||||
foreach ($indexes as $index) {
|
||||
$productIds[] = $keys[$index];
|
||||
}
|
||||
if ($RedisCacheService->exists($takenKey)) {
|
||||
return $RedisCacheService->get($dataKey);
|
||||
}
|
||||
$keys = $RedisCacheService->sDiff($dataKey, $takenKey);
|
||||
$number = min(count($keys), 10);
|
||||
if ($number <= 0) {
|
||||
return [];
|
||||
}
|
||||
$indexes = array_rand($keys, $number);
|
||||
$productIds = [];
|
||||
foreach ($indexes as $index) {
|
||||
$productIds[] = $keys[$index];
|
||||
}
|
||||
$RedisCacheService->sAdd($takenKey, ...$productIds);
|
||||
$RedisCacheService->expire($takenKey, 60);
|
||||
|
Loading…
x
Reference in New Issue
Block a user