refactor(lock): BatchDispatchLock增加makeKey与getExistingValue便于复用
This commit is contained in:
@@ -22,10 +22,28 @@ class BatchDispatchLock
|
||||
int $ttlSeconds = 60,
|
||||
string $value = '1',
|
||||
): bool {
|
||||
$orderIds = array_values(array_map('intval', $orderIds));
|
||||
|
||||
$lockKey = $namespace . ':' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit);
|
||||
$lockKey = static::makeKey($namespace, $scope, $filterSummary, $orderIds, $limit);
|
||||
|
||||
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