refactor(lock): BatchDispatchLock增加makeKey与getExistingValue便于复用

This commit is contained in:
萝卜
2026-03-17 18:21:17 +08:00
parent 353ae1bcc2
commit 397717e9bc

View File

@@ -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);
}
}