refactor(lock): BatchDispatchLock增加makeKey与getExistingValue便于复用
This commit is contained in:
@@ -22,10 +22,28 @@ class BatchDispatchLock
|
|||||||
int $ttlSeconds = 60,
|
int $ttlSeconds = 60,
|
||||||
string $value = '1',
|
string $value = '1',
|
||||||
): bool {
|
): bool {
|
||||||
$orderIds = array_values(array_map('intval', $orderIds));
|
$lockKey = static::makeKey($namespace, $scope, $filterSummary, $orderIds, $limit);
|
||||||
|
|
||||||
$lockKey = $namespace . ':' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit);
|
|
||||||
|
|
||||||
return Cache::add($lockKey, $value, $ttlSeconds);
|
return Cache::add($lockKey, $value, $ttlSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int[] $orderIds
|
||||||
|
*/
|
||||||
|
public static function makeKey(
|
||||||
|
string $namespace,
|
||||||
|
string $scope,
|
||||||
|
string $filterSummary,
|
||||||
|
array $orderIds,
|
||||||
|
int $limit,
|
||||||
|
): string {
|
||||||
|
$orderIds = array_values(array_map('intval', $orderIds));
|
||||||
|
|
||||||
|
return $namespace . ':' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getExistingValue(string $lockKey): mixed
|
||||||
|
{
|
||||||
|
return Cache::get($lockKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user